{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "<div style=\"float:right\"><i>Peter Norvig<br>5 January 2016</i></div>\n",
    "\n",
    "# Countdown to 2016\n",
    "\n",
    "Alex Bellos [posed](http://www.theguardian.com/science/2016/jan/04/can-you-solve-it-complete-the-equation-10-9-8-7-6-5-4-3-2-1-2016) this New Year's puzzle:\n",
    "\n",
    "\n",
    "> Fill in the blanks so that this equation makes arithmetical sense:\n",
    "\n",
    "> `10 _ 9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 = 2016`\n",
    "\n",
    "> You are allowed to use *only* the four basic arithmetical operations: +, -, &times;, ÷. But brackets (parentheses) can be used wherever needed. So, for example, the solution could begin\n",
    "\n",
    "> `(10 - 9) / (8` ...\n",
    "\n",
    "> or\n",
    "\n",
    "> `10 + (9 - 8)` ...\n",
    "\n",
    "Let's see if we can solve this puzzle, and some of the related ones from Alex's [first](http://www.theguardian.com/science/2016/jan/04/can-you-solve-it-complete-the-equation-10-9-8-7-6-5-4-3-2-1-2016) and [second](http://www.theguardian.com/science/2016/jan/04/did-you-solve-it-complete-the-equation-10-9-8-7-6-5-4-3-2-1-2016) post.  We'll start with a  simpler version of the puzzle."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# Four Operators, No Brackets\n",
    "\n",
    "Suppose for the moment we are not allowed to use brackets.  Then there are nine blanks,  each of which can be filled by one of four operators, so the total number of possible expressions is:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "262144"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 ** 9"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "The function `itertools.product` can enumerate all the ways of filling 9 blanks with one of the four operators:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "262144"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import itertools\n",
    "\n",
    "operators = ('+', '-', '*', '/')\n",
    "    \n",
    "len(set(itertools.product(operators, repeat=9)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "So we can fill in the equation with each possible sequence of operations, and evaluate each string to see if it equals 2016. But we need to catch errors such as dividing by zero, so we'll define a wrapper function, `evaluate`, to do the `eval`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def evaluate(exp):\n",
    "    \"eval exp, or return None if there is an arithmetic error.\"\n",
    "    try:\n",
    "        return eval(exp)\n",
    "    except ArithmeticError:\n",
    "        return None\n",
    "\n",
    "def solve_no_brackets(operators, target=2016):\n",
    "    \"All solutions to the countdown puzzle (with no brackets).\"\n",
    "    exps = ('10{}9{}8{}7{}6{}5{}4{}3{}2{}1'.format(*ops)\n",
    "            for ops in itertools.product(operators, repeat=9))\n",
    "    return [exp for exp in exps if evaluate(exp) == target]\n",
    "\n",
    "solve_no_brackets(operators)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Too bad; we did all that work and didn't find a solution. What years *can* we find solutions for? Let's modify `solve_no_brackets` to take a collection of target years rather than a single one, and return a dict of the form `{year: 'expression'}` for each expression that evaluates to one of the target years:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1979: '10*9*8+7*6*5*4*3/2-1',\n",
       " 1980: '10*9*8+7*6*5*4*3/2/1',\n",
       " 1981: '10*9*8+7*6*5*4*3/2+1',\n",
       " 2013: '10*9*8*7/6/5*4*3-2-1',\n",
       " 2014: '10*9*8*7/6/5*4*3-2/1',\n",
       " 2015: '10*9*8*7/6/5*4*3-2+1',\n",
       " 2017: '10*9*8*7/6/5*4*3+2-1',\n",
       " 2018: '10*9*8*7/6/5*4*3+2/1',\n",
       " 2019: '10*9*8*7/6/5*4*3+2+1'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def solve_no_brackets(operators, targets):\n",
    "    \"All solutions to the countdown puzzle (with no brackets).\"\n",
    "    exps = ('10{}9{}8{}7{}6{}5{}4{}3{}2{}1'.format(*ops)\n",
    "            for ops in itertools.product(operators, repeat=9))\n",
    "    return {int(evaluate(exp)): exp for exp in exps if evaluate(exp) in targets}\n",
    "\n",
    "solve_no_brackets(operators, range(1900, 2100))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Interesting: in the 20th and 21st centuries, there are only two \"golden eras\" where the countdown equation works: the three year period centered on 1980, and the seven year period that is centered on 2016, but omits 2016. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# Four Operators, With Brackets\n",
    "\n",
    "Now let's return to the original puzzle, with the brackets. How many ways are there of bracketing an expression with 9 binary operators? I happen to remember that this is given by the [Catalan numbers](https://en.wikipedia.org/wiki/Catalan_number), and we can [look it up](http://www.wolframalpha.com/input/?i=9th+catalan+number) to find that there are 4862 diffferent bracketing. If we enumerated and evaluated all of them, it would take about 4862 times longer than doing a single `solve_no_brackets`, which took about 6 seconds, so the estimated time would be about 8 hours. I'm impatient, so I'd like a faster approach. \n",
    "\n",
    "I'll use the idea of [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming): break the problem down into simpler subparts, and compute an answer for each subpart, and store intermediate results in a table so we don't need to re-compute them when we need them again.\n",
    "\n",
    "How do we break the problem into parts? In general, any expression must consist of an operator with two operands (which might in turn be complex subexpressions). For example, a complete countdown expression might be of the form\n",
    "\n",
    "    (10 ... 8) + (7 ... 1)\n",
    "    \n",
    "where `(10 ... 8)` means some expression that starts with 10 and ends with 8.  Of course we need not use `'+'` as the operator, and we need not split after the 8; we could use any of the four operators and split anywhere.  Let's start by defining `c10` as the tuple of integers forming the countdown from 10 to 1,  and the function `splits` to split a tuple in all ways: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "button": false,
    "collapsed": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "c10 = (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)\n",
    "\n",
    "def splits(items):\n",
    "    \"Split sequence of items into two non-empty parts, in all ways.\"\n",
    "    return [(items[:i], items[i:]) \n",
    "            for i in range(1, len(items))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[((10,), (9, 8, 7, 6, 5, 4, 3, 2, 1)),\n",
       " ((10, 9), (8, 7, 6, 5, 4, 3, 2, 1)),\n",
       " ((10, 9, 8), (7, 6, 5, 4, 3, 2, 1)),\n",
       " ((10, 9, 8, 7), (6, 5, 4, 3, 2, 1)),\n",
       " ((10, 9, 8, 7, 6), (5, 4, 3, 2, 1)),\n",
       " ((10, 9, 8, 7, 6, 5), (4, 3, 2, 1)),\n",
       " ((10, 9, 8, 7, 6, 5, 4), (3, 2, 1)),\n",
       " ((10, 9, 8, 7, 6, 5, 4, 3), (2, 1)),\n",
       " ((10, 9, 8, 7, 6, 5, 4, 3, 2), (1,))]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "splits(c10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Now what I would like to do is build up a table that says, for every subsequence of the numbers,  what are the expressions we can make with those numbers, and what do they evaluate to? We'll call the table `EXPS`. For example, with the subsequence `(10, 9, 8)`, we would have:\n",
    "\n",
    "    EXPS[(10, 9, 8)] = {\n",
    "      27: '((10+9)+8)',\n",
    "      8:  '((10-9)*8)', \n",
    "      -7: '(10-(9+8))', \n",
    "      ...}\n",
    "     \n",
    "We'll do the same for every other subsequence, for example:\n",
    "\n",
    "    EXPS[(7, 6, 5, 4, 3, 2, 1)] = {\n",
    "      1:   '((((7/((6/5)-4))+3)*2)*1)',\n",
    "      2:   '((((7/((6/5)-4))+3)*2)+1)',\n",
    "      3.5: '((((7/((6/5)-4))+3)+2)+1)',\n",
    "      4:   '((7-((6/5)*((4/3)+2)))+1)',\n",
    "      ...}\n",
    "     \n",
    "Once we have the tables for these two subsequences, we can put them together to get the table for the complete  `countdown(10)` by considering all ways of taking a value from the first table, then one of the four operators, then a value from the second table.  For example, taking the first entry from each table, and the operator `'+'`, we would have:\n",
    "\n",
    "    EXPS[(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)] = { \n",
    "      28: '(((10+9)+8)+((((7/((6/5)-4))+3)*2)*1))',\n",
    "      ...}\n",
    "\n",
    "\n",
    "I can implement `EXPS` as a defaultdict of dicts, and define `expressions(numbers)` to fill in `EXPS` entries for `numbers` and all sub-sequences of `numbers`.  Within `fill_tables`, note that `Lnums` and `Rnums` are sequences of numbers, such as `(10, 9, 8)` and `(7, 6)`. `L` and `R` are values, such as `27` and `1`. And `Lexp` and `Rexp` are strings, such as `\"((10+9)+8)\"` and `\"(7-6)\"`. Rather than catching division-by-zero errors, we just avoid the division when the denominator is 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "from collections import defaultdict, Counter\n",
    "\n",
    "EXPS = defaultdict(dict) # e.g., EXPS[(10, 9, 8)][27] == '((10+9)+8)'\n",
    "\n",
    "def expressions(numbers):\n",
    "    \"Fill EXPS table for numbers, and all sub-sequences of numbers. Return EXPS[numbers]\"\n",
    "    if numbers in EXPS: # Already did the work\n",
    "        pass\n",
    "    elif len(numbers) == 1: # Only one way to make an expression out of a single number\n",
    "        expr(numbers, numbers[0], str(numbers[0]))\n",
    "    else: # Split in all ways; fill tables for left and right; combine tables in all ways\n",
    "        for (Lnums, Rnums) in splits(numbers):\n",
    "            for (L, R) in itertools.product(expressions(Lnums), expressions(Rnums)):\n",
    "                Lexp, Rexp = '(' + EXPS[Lnums][L], EXPS[Rnums][R] + ')'\n",
    "                if R != 0: \n",
    "                    expr(numbers, L / R, Lexp + '/' + Rexp)\n",
    "                expr(numbers, L * R, Lexp + '*' + Rexp)\n",
    "                expr(numbers, L - R, Lexp + '-' + Rexp)\n",
    "                expr(numbers, L + R, Lexp + '+' + Rexp)\n",
    "    return EXPS[numbers]\n",
    "\n",
    "def expr(numbers, value, exp): \n",
    "    \"Record exp as an expression with the given value, covering the sequence of numbers.\"\n",
    "    EXPS[numbers][value] = exp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Let's give it a try:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{-62: '(10-(9*8))',\n",
       " -7: '((10-9)-8)',\n",
       " -6.888888888888889: '((10/9)-8)',\n",
       " 0.125: '((10-9)/8)',\n",
       " 0.1388888888888889: '((10/9)/8)',\n",
       " 0.5882352941176471: '(10/(9+8))',\n",
       " 2.375: '((10+9)/8)',\n",
       " 8: '((10-9)*8)',\n",
       " 8.875: '(10-(9/8))',\n",
       " 8.88888888888889: '((10/9)*8)',\n",
       " 9: '((10-9)+8)',\n",
       " 9.11111111111111: '((10/9)+8)',\n",
       " 10.0: '(10*(9-8))',\n",
       " 11: '((10+9)-8)',\n",
       " 11.125: '(10+(9/8))',\n",
       " 11.25: '((10*9)/8)',\n",
       " 27: '((10+9)+8)',\n",
       " 82: '((10*9)-8)',\n",
       " 98: '((10*9)+8)',\n",
       " 152: '((10+9)*8)',\n",
       " 170: '(10*(9+8))',\n",
       " 720: '((10*9)*8)'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expressions((10, 9, 8))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'((10+9)+8)'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EXPS[(10, 9, 8)][27]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "That looks reasonable. Let's solve the whole puzzle.\n",
    "\n",
    "# Countdown to 2016: A Solution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 29.1 s, sys: 713 ms, total: 29.8 s\n",
      "Wall time: 29.8 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'(((((((10+((9*8)*7))-6)-5)*4)+3)+2)-1)'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%time expressions(c10)[2016]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "We have an answer! And in a lot less than 8 hours, thanks to dynamic programming! \n",
    "\n",
    "Removing unnecessry brackets, this equation is equivalent to:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2016"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(10 + 9 * 8 * 7 - 6 - 5) * 4 + 3 + 2 - 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# Counting Solutions\n",
    "\n",
    "Alex Bellos had another challenge:  \n",
    "\n",
    "> I was half hoping a computer scientist would let me know exactly how many solutions there are with only the four basic operations. Maybe someone will. \n",
    "\n",
    "As it stands, my program can't answer that question, because I only keep one expression for each value. \n",
    "\n",
    "Also, I'm not sure what it means to be a distinct solution. For example, are `((10+9)+8)` and `(10+(9+8))` different, or are they same, because they both are equivalent to `(10+9+8)`? Similarly, are `((3-2)-1)` and `(3-(2+1)` different, or the same because they both are equivalent to `(3 + -2 + -1)`? I think the notion of \"distinct solution\" is just inherently ambiguous, and each of these questions could reasonably be answered either way. My choice is to count each of these as distinct: every expression has exactly ten numbers, nine operators, and nine pairs of brackets, and if an expression differs in any character, it is different. But I won't argue with anyone who has a different definition of \"distinct solution.\"\n",
    "\n",
    "So how can I count expressions? One approach would be to go back to enumerating every equation (all 4862 &times; 4<sup>9</sup> = 1.2 bilion of them) and checking which ones equal 2016. That would take about 40 hours with my Python program, but I could get it under 40 minutes in a more efficient language.\n",
    "\n",
    "Another approach is to count subexpressions as the table is filled in. We won't enumerate all the expressions, just count them. I'll introduce a second table, `COUNTS`, such that\n",
    "\n",
    "    COUNTS[(10, 9, 8)][27] == 2\n",
    "    \n",
    "because there are 2 ways to make 27 with the numbers `(10, 9, 8)`, namely, `((10+9)+8)` and `(10+(9+8))`.\n",
    "How do we compute the counts? By looking at every split and operator choice that can make the value, and summing up (over all of these) the product of the counts for the two sides.  For example, there are 2 ways to make 27 with `(10 ... 8)`, and it turns out there are 3526 ways to make 1 with `(7 ... 1)`. So there are 2 &times; 3526 = 7052 ways to make 28 with this split by adding 27 and 1. \n",
    "\n",
    "I'll make `expr` handle `COUNTS` as well as `EXPS`. And I'll define  `clear` to clear out the cache of `COUNTS` and `EXPS`, so that we can fill the tables with our new, improved entries."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "COUNTS = defaultdict(Counter) # e.g., COUNTS[(10, 9, 8)][27] == 2\n",
    "\n",
    "def expressions(numbers):\n",
    "    \"Fill EXPS table for numbers, and all sub-sequences of numbers. Return EXPS[numbers]\"\n",
    "    if numbers in EXPS: # Already did the work\n",
    "        pass\n",
    "    elif len(numbers) == 1: # Only one way to make an expression out of a single number\n",
    "        expr(numbers, numbers[0], str(numbers[0]), 1)\n",
    "    else: # Split in all ways; fill tables for left and right; combine tables in all ways\n",
    "        for (Lnums, Rnums) in splits(numbers):\n",
    "            for (L, R) in itertools.product(expressions(Lnums), expressions(Rnums)):\n",
    "                Lexp, Rexp = '(' + EXPS[Lnums][L], EXPS[Rnums][R] + ')'\n",
    "                count = COUNTS[Lnums][L] * COUNTS[Rnums][R]\n",
    "                if R != 0: \n",
    "                    expr(numbers, L / R, Lexp + '/' + Rexp, count)\n",
    "                expr(numbers, L * R, Lexp + '*' + Rexp, count)\n",
    "                expr(numbers, L - R, Lexp + '-' + Rexp, count)\n",
    "                expr(numbers, L + R, Lexp + '+' + Rexp, count)\n",
    "    return EXPS[numbers]\n",
    "\n",
    "def expr(numbers, val, exp, count):\n",
    "    \"Fill EXPS[numbers][val] with exp, and increment COUNTS.\"\n",
    "    EXPS[numbers][val] = exp\n",
    "    COUNTS[numbers][val] += count\n",
    "    \n",
    "def clear(): EXPS.clear(); COUNTS.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{-62: '(10-(9*8))',\n",
       " -7: '((10-9)-8)',\n",
       " -6.888888888888889: '((10/9)-8)',\n",
       " 0.125: '((10-9)/8)',\n",
       " 0.1388888888888889: '((10/9)/8)',\n",
       " 0.5882352941176471: '(10/(9+8))',\n",
       " 2.375: '((10+9)/8)',\n",
       " 8: '((10-9)*8)',\n",
       " 8.875: '(10-(9/8))',\n",
       " 8.88888888888889: '((10/9)*8)',\n",
       " 9: '((10-9)+8)',\n",
       " 9.11111111111111: '((10/9)+8)',\n",
       " 10.0: '(10*(9-8))',\n",
       " 11: '((10+9)-8)',\n",
       " 11.125: '(10+(9/8))',\n",
       " 11.25: '((10*9)/8)',\n",
       " 27: '((10+9)+8)',\n",
       " 82: '((10*9)-8)',\n",
       " 98: '((10*9)+8)',\n",
       " 152: '((10+9)*8)',\n",
       " 170: '(10*(9+8))',\n",
       " 720: '((10*9)*8)'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clear()\n",
    "expressions((10, 9, 8))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Counter({-62: 1,\n",
       "         -7: 2,\n",
       "         -6.888888888888889: 1,\n",
       "         0.125: 1,\n",
       "         0.1388888888888889: 2,\n",
       "         0.5882352941176471: 1,\n",
       "         2.375: 1,\n",
       "         8: 1,\n",
       "         8.875: 1,\n",
       "         8.88888888888889: 2,\n",
       "         9: 2,\n",
       "         9.11111111111111: 1,\n",
       "         10.0: 2,\n",
       "         11: 2,\n",
       "         11.125: 1,\n",
       "         11.25: 2,\n",
       "         27: 2,\n",
       "         82: 2,\n",
       "         98: 1,\n",
       "         152: 1,\n",
       "         170: 1,\n",
       "         720: 2})"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "COUNTS[(10, 9, 8)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "COUNTS[(10, 9, 8)][27]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Looks good to me. Now let's repeat the computation, this time keeping track of `COUNTS`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 1min 4s, sys: 1.12 s, total: 1min 5s\n",
      "Wall time: 1min 5s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'(((((((10+((9*8)*7))-6)-5)*4)+3)+2)-1)'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clear()\n",
    "\n",
    "%time expressions(c10)[2016]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# The Answer (?)\n",
    "\n",
    "Now we can read off the answer:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30066"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "COUNTS[c10][2016]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "This says there are 30,066 distinct expressions for 2016. \n",
    "\n",
    "**But I don't believe it.**\n",
    "\n",
    "Why not? Because floating point division can have round-off errors.  For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2015.9999999999998"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2015 + 1/3 + 1/3 + 1/3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2015 + 1/3 + 1/3 + 1/3 == 2016"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# Dealing with Round-off Errors\n",
    "\n",
    "So there might be perfectly good solutions that are hiding in the `EXPS` table under `2015.9999999999998` (or some similar number) when they should be exactly `2016`. Let's find all the values that are very near to `2016`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{2015.999999999997,\n",
       " 2015.999999999999,\n",
       " 2015.9999999999993,\n",
       " 2015.9999999999995,\n",
       " 2015.9999999999998,\n",
       " 2016.0,\n",
       " 2016.0000000000002,\n",
       " 2016.0000000000005,\n",
       " 2016.0000000000018,\n",
       " 2016.000000000002,\n",
       " 2016.0000000000023}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{val for val in expressions(c10)\n",
    " if abs(val - 2016) < 0.000001}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "I suspect that all of these actually should be exactly 2016. \n",
    "\n",
    "To find out for sure, let's re-do all the calculations using exact rational arithmetic, as provided by the `fractions.Fraction` data type. From experience I know that this will be an order of magnitude slower, so we're looking at 10 minutes or more of computation.\n",
    "\n",
    "I'll replace the computation `L / R` with `divide(L, R)`, which calls `Fraction`. To mitigate the expense of this computation, I make two optimizations. First, `divide` replaces a whole fraction, such as `Fraction(6, 2)`, with an `int`, such as `3`. Second, I modify `expr` to *not* fill in  `EXPS[c10]`, except for `EXPS[c10][2016]`. The rationale is that we don't need the other entries, and by not storing them, we save a lot of memory, and thus save garbage collection time."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "button": false,
    "collapsed": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "from fractions import Fraction\n",
    "\n",
    "def expressions(numbers):\n",
    "    \"Fill EXPS table for numbers, and all sub-sequences of numbers. Return EXPS[numbers]\"\n",
    "    if numbers in EXPS: # Already did the work\n",
    "        pass\n",
    "    elif len(numbers) == 1: # Only one way to make an expression out of a single number\n",
    "        expr(numbers, numbers[0], str(numbers[0]), 1)\n",
    "    else: # Split in all ways; fill tables for left and right; combine tables in all ways\n",
    "        for (Lnums, Rnums) in splits(numbers):\n",
    "            for (L, R) in itertools.product(expressions(Lnums), expressions(Rnums)):\n",
    "                Lexp, Rexp = '(' + EXPS[Lnums][L], EXPS[Rnums][R] + ')'\n",
    "                count = COUNTS[Lnums][L] * COUNTS[Rnums][R]\n",
    "                if R != 0: \n",
    "                    expr(numbers, divide(L, R), Lexp + '/' + Rexp, count)\n",
    "                expr(numbers, L * R, Lexp + '*' + Rexp, count)\n",
    "                expr(numbers, L - R, Lexp + '-' + Rexp, count)\n",
    "                expr(numbers, L + R, Lexp + '+' + Rexp, count)\n",
    "    return EXPS[numbers]\n",
    "\n",
    "def divide(L, R):\n",
    "    \"Exact rational division of L/R.\"\n",
    "    f = Fraction(L, R)\n",
    "    return (f.numerator if f.denominator == 1 else f)\n",
    "\n",
    "def expr(numbers, value, exp, count):\n",
    "    \"Fill EXPS[numbers][val] with exp, and increment COUNTS.\"\n",
    "    if numbers == c10 and value != 2016: \n",
    "        return\n",
    "    EXPS[numbers][value] = exp\n",
    "    COUNTS[numbers][value] += count"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# The Answer (!)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 12min 25s, sys: 1.44 s, total: 12min 26s\n",
      "Wall time: 12min 27s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "44499"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clear()\n",
    "\n",
    "%time expressions(c10)[2016]\n",
    "\n",
    "COUNTS[c10][2016]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "That did indeed take about ten times longer, but we now have an answer that I have more confidence in (but I wouldn't accept it as definitive until it was independently verified and had an extensive test suite). And of course, if you have a different definition of \"distinct solution,\" you will get a different answer."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# Dealing with the Exponentiation Operator\n",
    "\n",
    "Now let's turn to another of Alex's puzzles: making 2016 and other target values from a string of four or five `4`s,  with exponentiation allowed. Exponentiation is tricky for five reasons:\n",
    "\n",
    "- **Division by zero**: `(0 ** -1)` is the same as `(1 / 0)`, and gives a `ZeroDivisionError`.\n",
    "- **Irrationals**: `(3 ** (1 / 2))` is an irrational number; so we can't do exact rational arithmetic.\n",
    "- **Imaginaries**: `(-1 ** (1 / 2))` is an imaginary number, but Python gives a `ValueError`.\n",
    "- **Overflow**: `(10. ** (9. ** 8.))`, as a `float`, gives a `OverflowError`.\n",
    "- **Finite memory**: [`(10 ** (9 ** (8 * 7)))`](http://www.wolframalpha.com/input/?i=10+%5E+9+%5E+56), as an `int`, gives an `OutOfMemoryError` (even if your memory was expanded to use every atom on Earth).\n",
    "\n",
    "How do we deal with this? We can't do exact rational arithmetic. We could try to do exact *algebra*, perhaps using [SymPy](http://www.sympy.org/en/index.html), but that seems difficult\n",
    "and computationally expensive, so instead I will abandon the goal of exact computation, and do everything in the domain of floats (reluctantly accepting that there will be some round-off errors). We'll coerce numbers to floats when we first put them in the table, and all subsequent operations will be with floats. I define a new function, `expr2`,  to call `expr`, catching arithmetic errors. Since we are making some rather arbitrary decisions about what expressions are allowed (e.g. imaginary numbers are not), I'll give up on trying to maintain `COUNTS`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "from operator import add, sub, mul, truediv\n",
    "\n",
    "def expressions(numbers):\n",
    "    \"Fill EXPS table for numbers, and all sub-sequences of numbers. Return EXPS[numbers]\"\n",
    "    if numbers in EXPS: # Already did the work\n",
    "        pass\n",
    "    elif len(numbers) == 1: # Only one way to make an expression out of a single number\n",
    "        expr(numbers, float(numbers[0]), str(numbers[0]))\n",
    "    else: # Split in all ways; fill tables for left and right; combine tables in all ways\n",
    "        for (Lnums, Rnums) in splits(numbers):\n",
    "            for (L, R) in itertools.product(expressions(Lnums), expressions(Rnums)):\n",
    "                Lexp, Rexp = '(' + EXPS[Lnums][L], EXPS[Rnums][R] + ')'\n",
    "                expr2(numbers, L, pow,     R, Lexp + '**' + Rexp)\n",
    "                expr2(numbers, L, truediv, R, Lexp + '/'  + Rexp)\n",
    "                expr2(numbers, L, mul,     R, Lexp + '*'  + Rexp)\n",
    "                expr2(numbers, L, add,     R, Lexp + '+'  + Rexp)\n",
    "                expr2(numbers, L, sub,     R, Lexp + '-'  + Rexp)\n",
    "    return EXPS[numbers]\n",
    "\n",
    "def expr2(numbers, L, op, R, exp): \n",
    "    \"Fill table entries for op(L, R), catching errors.\"\n",
    "    try:\n",
    "        expr(numbers, op(L, R), exp)\n",
    "    except (ArithmeticError, ValueError):\n",
    "        pass\n",
    "    \n",
    "def expr(numbers, value, exp): EXPS[numbers][value] = exp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Now we can solve the \"2016 with five fours\" puzzle:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'(((4**4)-4)*(4+4))'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clear()\n",
    "\n",
    "expressions((4, 4, 4, 4, 4))[2016]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "I'll define a function to create a table of makeable integers:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "def makeable(numbers):\n",
    "    \"A table of {i: expression} for all integers i from 0 up to first unmakeable.\"\n",
    "    return {i: expressions(numbers)[i]\n",
    "            for i in range(unmakeable(numbers))}\n",
    "\n",
    "def unmakeable(numbers):\n",
    "    \"Smallest positive integer than can't be made by numbers.\"\n",
    "    return next(i for i in itertools.count(1) if i not in expressions(numbers))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "We'll use this to see if we can solve the \"0 to 9 with four fours\" puzzle:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: '(((4+4)-4)-4)',\n",
       " 1: '(((4+4)-4)/4)',\n",
       " 2: '((4/(4+4))*4)',\n",
       " 3: '(((4+4)+4)/4)',\n",
       " 4: '(((4-4)*4)+4)',\n",
       " 5: '(((4*4)+4)/4)',\n",
       " 6: '(((4+4)/4)+4)',\n",
       " 7: '((4-(4/4))+4)',\n",
       " 8: '(((4+4)-4)+4)',\n",
       " 9: '(((4/4)+4)+4)'}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "makeable((4, 4, 4, 4))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Yes: we can get 0 to 9 (but not 10).\n",
    "\n",
    "Now I'll see what integers we can make with five fives. Legend has it that you can get all the way up to 55:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: '((((5-5)*5)-5)+5)',\n",
       " 1: '(((5-(5*5))/5)+5)',\n",
       " 2: '((((5+5)/5)-5)+5)',\n",
       " 3: '((((5*5)-5)-5)/5)',\n",
       " 4: '((((5-5)-5)/5)+5)',\n",
       " 5: '((5/((5**5)**5))+5)',\n",
       " 6: '((((5/5)+5)*5)/5)',\n",
       " 7: '(((5/5)+(5/5))+5)',\n",
       " 8: '((((5+5)+5)/5)+5)',\n",
       " 9: '((((5+5)*5)-5)/5)',\n",
       " 10: '((((5*5)-5)-5)-5)',\n",
       " 11: '((((5+5)*5)+5)/5)',\n",
       " 12: '((((5+5)/5)+5)+5)'}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ff = (5, 5, 5, 5, 5)\n",
    "\n",
    "makeable(ff)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "We didn't get there. \n",
    "\n",
    "# More Operations\n",
    "\n",
    "With some research, I [see](http://www.infobarrel.com/Five_Fives_Problem_Recreational_Mathematics) that others who got up to 55 with five 5s used these three concepts:\n",
    "\n",
    "- **digit concatenation**: `55`\n",
    "- **decimal point**: `.5`\n",
    "- **unary operations**: `5!` and  &radic; `5`\n",
    "\n",
    "\n",
    "We'll refactor `expressions` to call these three new subfunctions:\n",
    "\n",
    "- `digit_expressions`: For every subsequence of numbers, we'll smush the digits together, and then make a table entry for those resulting digits as an integer, and with a decimal point in each possible position.\n",
    "- `binary_expressions`: The code that previously was the main body of `expressions`.\n",
    "- `unary_expressions`: Apply the unary operators to every entry in the table. (Because it applies to entries already in the table, make sure to call `unary_expressions` last.)\n",
    "\n",
    "We'll still do all computation in the domain of floats."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "from math import sqrt, factorial\n",
    "\n",
    "def expressions(numbers):\n",
    "    \"Fill EXPS table for numbers, and all sub-sequences of numbers. Return EXPS[numbers]\"\n",
    "    if numbers not in EXPS: \n",
    "        digit_expressions(numbers)\n",
    "        binary_expressions(numbers)\n",
    "        unary_expressions(numbers)\n",
    "    return EXPS[numbers]\n",
    "\n",
    "def digit_expressions(numbers):\n",
    "    \"Fill tables with expressions made from the digits of numbers, and a decimal point.\"\n",
    "    exp = ''.join(str(n) for n in numbers)\n",
    "    expr(numbers, float(exp), exp)\n",
    "    for d in range(len(exp)):\n",
    "        decimal = exp[:d] + '.' + exp[d:]\n",
    "        expr(numbers, float(decimal), decimal)\n",
    "            \n",
    "def binary_expressions(numbers):\n",
    "    \"Fill tables with all expressions formed by splitting numbers and combining with an op.\"\n",
    "    for (Lnums, Rnums) in splits(numbers):\n",
    "        for (L, R) in itertools.product(expressions(Lnums), expressions(Rnums)):\n",
    "            Lexp, Rexp = '(' + EXPS[Lnums][L], EXPS[Rnums][R] + ')'\n",
    "            if 1 <= R <= 10 and (L > 0 or int(R) == R):\n",
    "                expr2(numbers, L, pow, R, Lexp + '**' + Rexp)\n",
    "            expr2(numbers, L, truediv, R, Lexp + '/'  + Rexp)\n",
    "            expr2(numbers, L, mul,     R, Lexp + '*'  + Rexp)\n",
    "            expr2(numbers, L, add,     R, Lexp + '+'  + Rexp)\n",
    "            expr2(numbers, L, sub,     R, Lexp + '-'  + Rexp)\n",
    "            \n",
    "def unary_expressions(numbers):\n",
    "    for v in list(EXPS[numbers]):\n",
    "        exp = EXPS[numbers][v]\n",
    "        if v > 0: \n",
    "            expr(numbers, sqrt(v), '√' + exp)\n",
    "        if 2 <= v <= 6 and v == int(v):\n",
    "            expr(numbers, factorial(v), exp + '!')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Now that we have more variety in the types of expressions formed, I want to choose a \"good\" expression to represent each value. I'll modify `expr` so that when there are multiple expressions for a value, it chooses the one with the least \"weight,\" where I define `weight` as the length of the string, plus a penalty of 1 for every square root sign (just because square root feels \"heavier\" than the other operations):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "button": false,
    "collapsed": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "def expr(numbers, value, exp): \n",
    "    if value not in EXPS[numbers] or weight(exp) < weight(EXPS[numbers][value]):\n",
    "        EXPS[numbers][value] = exp\n",
    "        \n",
    "def weight(exp): return len(exp) + exp.count('√')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "We'll try again:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 43.5 s, sys: 1.44 s, total: 45 s\n",
      "Wall time: 45 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{0: '(5*(55-55))',\n",
       " 1: '((55/55)**5)',\n",
       " 2: '(55/(.5*55))',\n",
       " 3: '√(5!-(555/5))',\n",
       " 4: '(5-(55/55))',\n",
       " 5: '(5.55-.55)',\n",
       " 6: '(5+(55/55))',\n",
       " 7: '(((5+55)/5)-5)',\n",
       " 8: '(.5*(5+(55/5)))',\n",
       " 9: '(5!-(555/5))',\n",
       " 10: '(5!-(55+55))',\n",
       " 11: '(5.5/(5.5-5))',\n",
       " 12: '(5!/(55/5.5))',\n",
       " 13: '((5+(5+55))/5)',\n",
       " 14: '((5*5)-(55/5))',\n",
       " 15: '(5+(55/5.5))',\n",
       " 16: '(5+(5.5+5.5))',\n",
       " 17: '(5+((5+55)/5))',\n",
       " 18: '(5+((5!-55)/5))',\n",
       " 19: '((5*5)-(.5+5.5))',\n",
       " 20: '(55/(5*.55))',\n",
       " 21: '(5+(5+(55/5)))',\n",
       " 22: '((55+55)/5)',\n",
       " 23: '((5+(55/.5))/5)',\n",
       " 24: '(5-(55/55))!',\n",
       " 25: '(55-(5+(5*5)))',\n",
       " 26: '(55-(5+(5!/5)))',\n",
       " 27: '(.5*(55-(5/5)))',\n",
       " 28: '(.5*(.5+55.5))',\n",
       " 29: '(5+(5!/(5.5-.5)))',\n",
       " 30: '(5*((55/5)-5))',\n",
       " 31: '(55-(5-(5/5))!)',\n",
       " 32: '(55-((5!-5)/5))',\n",
       " 33: '(.55*(5+55))',\n",
       " 34: '((5!+(55-5))/5)',\n",
       " 35: '(5+(55-(5*5)))',\n",
       " 36: '((5*5)+(55/5))',\n",
       " 37: '((5!+(5!-55))/5)',\n",
       " 38: '(5+(.5*(5!*.55)))',\n",
       " 39: '(((5*5)-5.5)/.5)',\n",
       " 40: '(55-(5+(5+5)))',\n",
       " 41: '(5!-((5!/5)+55))',\n",
       " 42: '((5+5.5)/(.5*.5))',\n",
       " 43: '(55-(5!/(5+5)))',\n",
       " 44: '(55-(55/5))',\n",
       " 45: '((5*5!)-555)',\n",
       " 46: '(55-((5-.5)/.5))',\n",
       " 47: '((5!/5)+((5!-5)/5))',\n",
       " 48: '(5!/(5*(5.5-5)))',\n",
       " 49: '(55-(.5+5.5))',\n",
       " 50: '(55.5-5.5)',\n",
       " 51: '(.5+(55.5-5))',\n",
       " 52: '(55-(.5+(.5*5)))',\n",
       " 53: '(55.5-(.5*5))',\n",
       " 54: '(((5*55)-5)/5)',\n",
       " 55: '(.5*(55+55))',\n",
       " 56: '((5+(5*55))/5)',\n",
       " 57: '(55+((5+5)/5))',\n",
       " 58: '((.5*5)+55.5)',\n",
       " 59: '(5+(55-(5/5)))',\n",
       " 60: '(5+(55.5-.5))',\n",
       " 61: '(5.5+55.5)',\n",
       " 62: '((55-(5!/5))/.5)',\n",
       " 63: '(5.5+(.5*(5!-5)))',\n",
       " 64: '(5!-(.5+55.5))',\n",
       " 65: '(.5+(5!-55.5))',\n",
       " 66: '(55+(55/5))',\n",
       " 67: '(55+(5!/(5+5)))',\n",
       " 68: '(5.5+(.5*(5+5!)))',\n",
       " 69: '(5!-((.5+(5*5))/.5))',\n",
       " 70: '(5+(5+(5+55)))',\n",
       " 71: '((.5*5!)+(55/5))',\n",
       " 72: '((.5+5.5)!/(5+5))',\n",
       " 73: '((5*5)+(5!/(.5*5)))',\n",
       " 74: '((5!/5)+(55-5))',\n",
       " 75: '((5*5)+(55-5))',\n",
       " 76: '(5+(5+(5!*.55)))',\n",
       " 77: '(5+(.5*(5!+(5!/5))))',\n",
       " 78: '(55+((5!-5)/5))',\n",
       " 79: '(55+(5-(5/5))!)',\n",
       " 80: '(5*(5+(55/5)))',\n",
       " 81: '((√.5+(5!/√(5-.5)))/√.5)',\n",
       " 82: '(5!-(((5!/5)-5)/.5))',\n",
       " 83: '((.5*5!)+((5!-5)/5))',\n",
       " 84: '(5+((5!/5)+55))',\n",
       " 85: '(5+((5*5)+55))',\n",
       " 86: '((55/.5)-(5!/5))',\n",
       " 87: '((555-5!)/5)',\n",
       " 88: '(.5+(.5*(5!+55)))',\n",
       " 89: '(5!-(55-(5!/5)))',\n",
       " 90: '(5!-(55-(5*5)))',\n",
       " 91: '((5*5)+(5!*.55))',\n",
       " 92: '(5!-(.5+(.5*55)))',\n",
       " 93: '(.5+(5!-(.5*55)))',\n",
       " 94: '(5!-((5/5)+(5*5)))',\n",
       " 95: '(((55-5)/.5)-5)',\n",
       " 96: '(5!-(5!/(5.5-.5)))',\n",
       " 97: '(5!-((5!/5)-(5/5)))',\n",
       " 98: '(5!-(55/(.5*5)))',\n",
       " 99: '((55-5.5)/.5)',\n",
       " 100: '((55/.5)-(5+5))',\n",
       " 101: '((55.5-5)/.5)',\n",
       " 102: '(5+(5!-((5!-5)/5)))',\n",
       " 103: '(55+(5!/(.5*5)))',\n",
       " 104: '(5!-(5+(55/5)))',\n",
       " 105: '(55+(55-5))',\n",
       " 106: '((555/5)-5)',\n",
       " 107: '(5!-((5!-55)/5))',\n",
       " 108: '(5!-((5+55)/5))',\n",
       " 109: '(5!-(5.5+5.5))',\n",
       " 110: '((555-5)/5)',\n",
       " 111: '(555/√(5*5))',\n",
       " 112: '((5+555)/5)',\n",
       " 113: '(5!-(5+((5+5)/5)))',\n",
       " 114: '(5+(5!-(55/5)))',\n",
       " 115: '(5+(55+55))',\n",
       " 116: '(5+(555/5))',\n",
       " 117: '(5!-(5.5-(.5*5)))',\n",
       " 118: '(5!-(5!/(5+55)))',\n",
       " 119: '(5!-(55/55))',\n",
       " 120: '(5.55-.55)!',\n",
       " 121: '(5!+(55/55))',\n",
       " 122: '(5!+(5!/(5+55)))',\n",
       " 123: '(5!+(5.5-(.5*5)))',\n",
       " 124: '(5!+√(5+(55/5)))',\n",
       " 125: '(.5*(5*(55-5)))',\n",
       " 126: '(5!+((55/5)-5))',\n",
       " 127: '((5!/(5/5.5))-5)',\n",
       " 128: '(5!+(5.5+(.5*5)))',\n",
       " 129: '((5!-55.5)/.5)',\n",
       " 130: '(5!+(55/5.5))',\n",
       " 131: '(5!+(5.5+5.5))',\n",
       " 132: '(5!*(.55+.55))',\n",
       " 133: '(5!+((5!-55)/5))',\n",
       " 134: '((5!/5)+(55/.5))',\n",
       " 135: '((5!+555)/5)',\n",
       " 136: '(5+(5!+(55/5)))',\n",
       " 137: '(5+(5!/(5/5.5)))',\n",
       " 138: '(.5+(.5*(5*55)))',\n",
       " 139: '(((.5+5.5)!/5)-5)',\n",
       " 140: '(.5*(5+(5*55)))',\n",
       " 141: '(5!+((5+5.5)/.5))',\n",
       " 142: '(5!+(55/(.5*5)))',\n",
       " 143: '(((.5+5.5)!-5)/5)',\n",
       " 144: '(((55/5)-5)!/5)',\n",
       " 145: '(5!+(.5*(55-5)))',\n",
       " 146: '(5!+((5/5)+(5*5)))',\n",
       " 147: '(5!+((.5*55)-.5))',\n",
       " 148: '(.5+(5!+(.5*55)))',\n",
       " 149: '(5+((.5+5.5)!/5))',\n",
       " 150: '(5*(55-(5*5)))',\n",
       " 151: '(5!+(55-(5!/5)))',\n",
       " 152: '(5!+(((5+5)/5)**5))',\n",
       " 153: '(5!+(.5*(5!*.55)))',\n",
       " 154: '(5+(5+(5!+(5!/5))))',\n",
       " 155: '(5*(55-(5!/5)))',\n",
       " 156: '((5!+(5!*5.5))/5)'}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clear()\n",
    "\n",
    "%time makeable(ff)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Wow! We almost tripled the 55 goal! I have to say, I would never have come up with the solution for 81 on my own. It works because (√(5 - .5) \\* √0.5) = √(4.5 \\* 0.5) = (√2.25) = 1.5."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "# Even More Operations \n",
    "\n",
    "At the risk of making the computation take even longer, I'm going to add two more operations:\n",
    "\n",
    "- **Floor**: &lfloor;*x*&rfloor; is the largest integer less than or equal to *x* (in other words, rounding down).\n",
    "- **Ceiling**: &lceil;*x*&rceil; is the smallest integer greater than or equal to *x* (in other words, rounding up).\n",
    "\n",
    "These operations are useful because they produce integers, and our targets are the integers (from 0 up to whatever). \n",
    "\n",
    "In addition, I'll allow two consecutive applications of unary operators, thus allowing expressions such as\n",
    "\n",
    "- ⌊√5⌋ = 2\n",
    "- ⌈5.5⌉! = 720\n",
    "\n",
    "But still not allowing three consecutive applications, such as\n",
    "\n",
    "- ⌈√5⌉! = 6\n",
    "\n",
    "To compensate for these new expressions, I'll be pickier about when I allow the square root function to apply."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "button": false,
    "collapsed": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "from math import floor, ceil\n",
    "\n",
    "def unary_expressions(numbers):\n",
    "    for i in range(2):\n",
    "        for v in list(EXPS[numbers]):\n",
    "            exp = EXPS[numbers][v]\n",
    "            if 0 < v <= 100 and 4*v == round(4*v):\n",
    "                expr(numbers, sqrt(v), '√' + exp)\n",
    "            if 2 <= v <= 6 and v == round(v):\n",
    "                expr(numbers, factorial(v), exp + '!')\n",
    "            if v != round(v):\n",
    "                uexp = unbracket(exp)\n",
    "                expr(numbers, floor(v), '⌊' + uexp + '⌋')\n",
    "                expr(numbers, ceil(v),  '⌈' + uexp + '⌉')\n",
    "            \n",
    "def unbracket(exp):\n",
    "    \"Remove outer brackets from exp if they are there.\"\n",
    "    if exp.startswith('(') and exp.endswith(')'):\n",
    "        return exp[1:-1]\n",
    "    else:\n",
    "        return exp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Let's try:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 2min 25s, sys: 1.42 s, total: 2min 26s\n",
      "Wall time: 2min 26s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{0: '⌊.55555⌋',\n",
       " 1: '⌈.55555⌉',\n",
       " 2: '⌊5*.5555⌋',\n",
       " 3: '⌈5*.5555⌉',\n",
       " 4: '⌊5-.5555⌋',\n",
       " 5: '⌊5.5555⌋',\n",
       " 6: '⌈5.5555⌉',\n",
       " 7: '⌈.5+5.555⌉',\n",
       " 8: '⌈√55+.555⌉',\n",
       " 9: '⌊55/5.55⌋',\n",
       " 10: '⌊555/55⌋',\n",
       " 11: '⌈555/55⌉',\n",
       " 12: '⌈55.55/5⌉',\n",
       " 13: '⌈√5*5.555⌉',\n",
       " 14: '⌈√55/.555⌉',\n",
       " 15: '(5+(55/5.5))',\n",
       " 16: '(5+⌊55.5/5⌋)',\n",
       " 17: '(5+⌈55.5/5⌉)',\n",
       " 18: '⌊55/⌈5*.55⌉⌋',\n",
       " 19: '⌈55/⌈5*.55⌉⌉',\n",
       " 20: '(5*⌊5-.555⌋)',\n",
       " 21: '⌊5!/5.555⌋',\n",
       " 22: '⌈5!/5.555⌉',\n",
       " 23: '⌈555/(5*5)⌉',\n",
       " 24: '⌊5-.5555⌋!',\n",
       " 25: '(5*⌊5.555⌋)',\n",
       " 26: '(⌈.55*55⌉-5)',\n",
       " 27: '⌊5*5.555⌋',\n",
       " 28: '⌈5*5.555⌉',\n",
       " 29: '(5+⌊5-.555⌋!)',\n",
       " 30: '⌊55*.555⌋',\n",
       " 31: '⌈55*.555⌉',\n",
       " 32: '(5+⌊5*5.55⌋)',\n",
       " 33: '(5+⌈5*5.55⌉)',\n",
       " 34: '⌈⌈5.5⌉*5.55⌉',\n",
       " 35: '(5+⌊.55*55⌋)',\n",
       " 36: '(5+⌈.55*55⌉)',\n",
       " 37: '⌊5*(55/√55)⌋',\n",
       " 38: '⌊⌊√55⌋*5.55⌋',\n",
       " 39: '⌊√.5*55.55⌋',\n",
       " 40: '⌊5.5*√55.5⌋',\n",
       " 41: '⌊√55*5.55⌋',\n",
       " 42: '⌈√55*5.55⌉',\n",
       " 43: '(55-⌊5+√55⌋)',\n",
       " 44: '(55-(55/5))',\n",
       " 45: '(5*⌊5/.555⌋)',\n",
       " 46: '⌊5555/5!⌋',\n",
       " 47: '⌈5555/5!⌉',\n",
       " 48: '⌈55-√55.5⌉',\n",
       " 49: '⌊55-5.55⌋',\n",
       " 50: '⌊55.55-5⌋',\n",
       " 51: '⌈55.55-5⌉',\n",
       " 52: '(55-⌈5*.55⌉)',\n",
       " 53: '⌊55.55-√5⌋',\n",
       " 54: '⌊55-.555⌋',\n",
       " 55: '⌊55.555⌋',\n",
       " 56: '⌈55.555⌉',\n",
       " 57: '⌈.5+55.55⌉',\n",
       " 58: '⌈√5+55.55⌉',\n",
       " 59: '(5+⌊55-.55⌋)',\n",
       " 60: '⌊5+55.55⌋',\n",
       " 61: '⌈5+55.55⌉',\n",
       " 62: '⌊√55+55.5⌋',\n",
       " 63: '⌈√55+55.5⌉',\n",
       " 64: '⌊5!-55.55⌋',\n",
       " 65: '⌈5!-55.55⌉',\n",
       " 66: '⌊5!*.5555⌋',\n",
       " 67: '⌈5!*.5555⌉',\n",
       " 68: '(5+⌈55+√55⌉)',\n",
       " 69: '⌊555/⌈√55⌉⌋',\n",
       " 70: '⌈555/⌈√55⌉⌉',\n",
       " 71: '(5+⌊5!*.555⌋)',\n",
       " 72: '(5+⌈5!*.555⌉)',\n",
       " 73: '(5!-⌊55-√55⌋)',\n",
       " 74: '⌊555/√55⌋',\n",
       " 75: '⌈555/√55⌉',\n",
       " 76: '(55+⌊5!/5.5⌋)',\n",
       " 77: '(55+⌈5!/5.5⌉)',\n",
       " 78: '⌊55.55/√.5⌋',\n",
       " 79: '⌊555/⌊√55⌋⌋',\n",
       " 80: '⌊(5*5)+55.5⌋',\n",
       " 81: '⌈(5*5)+55.5⌉',\n",
       " 82: '(55+⌊.5*55⌋)',\n",
       " 83: '(55+⌈.5*55⌉)',\n",
       " 84: '(5+((5!/5)+55))',\n",
       " 85: '(5+(55+(5*5)))',\n",
       " 86: '⌊⌈5+55.5⌉/√.5⌋',\n",
       " 87: '((555-5!)/5)',\n",
       " 88: '⌈√5**5.555⌉',\n",
       " 89: '(5!-⌈.55*55⌉)',\n",
       " 90: '⌊(55-5)/.55⌋',\n",
       " 91: '⌈(55-5)/.55⌉',\n",
       " 92: '⌊555/⌈5.5⌉⌋',\n",
       " 93: '⌈555/⌈5.5⌉⌉',\n",
       " 94: '(⌊55/.55⌋-5)',\n",
       " 95: '(⌈55/.55⌉-5)',\n",
       " 96: '⌊.55*(5!+55)⌋',\n",
       " 97: '⌈.55*(5!+55)⌉',\n",
       " 98: '(⌊55-5.5⌋/.5)',\n",
       " 99: '⌊55/.555⌋',\n",
       " 100: '⌊555/5.5⌋',\n",
       " 101: '⌈555/5.5⌉',\n",
       " 102: '⌈⌈55.5⌉/.55⌉',\n",
       " 103: '⌊⌊√5+55⌋/.55⌋',\n",
       " 104: '(5+⌊55/.55⌋)',\n",
       " 105: '(55+(55-5))',\n",
       " 106: '((555/5)-5)',\n",
       " 107: '(55+⌊55-√5⌋)',\n",
       " 108: '(5!-⌈55.5/5⌉)',\n",
       " 109: '(55+⌊55-.5⌋)',\n",
       " 110: '⌊55+55.5⌋',\n",
       " 111: '⌈55+55.5⌉',\n",
       " 112: '⌈555.5/5⌉',\n",
       " 113: '(55+⌈√5+55⌉)',\n",
       " 114: '⌊5!-5.555⌋',\n",
       " 115: '⌈5!-5.555⌉',\n",
       " 116: '(5+(555/5))',\n",
       " 117: '(5!-⌈5*.555⌉)',\n",
       " 118: '(5!-⌈5.55/5⌉)',\n",
       " 119: '⌊5!-.5555⌋',\n",
       " 120: '⌊5.5555⌋!',\n",
       " 121: '⌈5!+.5555⌉',\n",
       " 122: '(5!+⌈5.55/5⌉)',\n",
       " 123: '⌊555/(5-.5)⌋',\n",
       " 124: '⌊√5*55.55⌋',\n",
       " 125: '⌊5!+5.555⌋',\n",
       " 126: '⌈5!+5.555⌉',\n",
       " 127: '⌊⌊5**5.5⌋/55⌋',\n",
       " 128: '⌈⌊5**5.5⌋/55⌉',\n",
       " 129: '(5!+⌊5/.555⌋)',\n",
       " 130: '⌊√5.5*55.5⌋',\n",
       " 131: '⌈√5.5*55.5⌉',\n",
       " 132: '(5!+⌈55.5/5⌉)',\n",
       " 133: '⌈55*(√55-5)⌉',\n",
       " 134: '⌊55*√⌈5.55⌉⌋',\n",
       " 135: '(5*⌊5*5.55⌋)',\n",
       " 136: '⌈√⌈5.5⌉*55.5⌉',\n",
       " 137: '⌊5.5*⌈55/√5⌉⌋',\n",
       " 138: '⌊5*(5*5.55)⌋',\n",
       " 139: '⌈5*(5*5.55)⌉',\n",
       " 140: '(5*⌈5*5.55⌉)',\n",
       " 141: '(5!+⌊5!/5.55⌋)',\n",
       " 142: '(5!+⌈5!/5.55⌉)',\n",
       " 143: '(5+⌈.5*(5*55)⌉)',\n",
       " 144: '(⌈5.555⌉!/5)',\n",
       " 145: '(5+(5*⌈.5*55⌉))',\n",
       " 146: '⌊55*(5-√5.5)⌋',\n",
       " 147: '(5!+⌊5*5.55⌋)',\n",
       " 148: '(5!+⌈5*5.55⌉)',\n",
       " 149: '⌈5.5*⌊.5*55⌋⌉',\n",
       " 150: '(5*⌊.55*55⌋)',\n",
       " 151: '⌊.55*(5*55)⌋',\n",
       " 152: '⌈.55*(5*55)⌉',\n",
       " 153: '⌊55*(√5+.55)⌋',\n",
       " 154: '(5.5*⌈.5*55⌉)',\n",
       " 155: '(5*⌈.55*55⌉)',\n",
       " 156: '⌈(55+55)/√.5⌉',\n",
       " 157: '(⌊.5*555⌋-5!)',\n",
       " 158: '(⌈.5*555⌉-5!)',\n",
       " 159: '(5!+⌊√.5*55.5⌋)',\n",
       " 160: '(5*(5+⌊.5*55⌋))',\n",
       " 161: '⌊(.5*5)**5.55⌋',\n",
       " 162: '⌈(.5*5)**5.55⌉',\n",
       " 163: '(⌊5!/.55⌋-55)',\n",
       " 164: '(⌈5!/.55⌉-55)',\n",
       " 165: '(55*⌈5*.55⌉)',\n",
       " 166: '⌊⌈.5*5⌉*55.5⌋',\n",
       " 167: '⌈⌈.5*5⌉*55.5⌉',\n",
       " 168: '(5!+⌈55-√55⌉)',\n",
       " 169: '(5!+⌊55-5.5⌋)',\n",
       " 170: '(5!+⌊55.5-5⌋)',\n",
       " 171: '(5!+⌈55.5-5⌉)',\n",
       " 172: '⌈5.555**⌈√5⌉⌉',\n",
       " 173: '⌊55*√⌊5+5.5⌋⌋',\n",
       " 174: '(5!+⌊55-.55⌋)',\n",
       " 175: '⌊5!+55.55⌋',\n",
       " 176: '⌈5!+55.55⌉',\n",
       " 177: '(55+⌊√5*55⌋)',\n",
       " 178: '(55+⌈√5*55⌉)',\n",
       " 179: '⌊55*(5.5-√5)⌋',\n",
       " 180: '(5+⌊5!+55.5⌋)',\n",
       " 181: '(5+⌈5!+55.5⌉)',\n",
       " 182: '(⌊5.5*55⌋-5!)',\n",
       " 183: '(⌈5.5*55⌉-5!)',\n",
       " 184: '(5!+⌊5!-55.5⌋)',\n",
       " 185: '(555/⌈.5*5⌉)',\n",
       " 186: '⌈555.5/⌈√5⌉⌉',\n",
       " 187: '(5!+⌈5!*.555⌉)',\n",
       " 188: '((⌈.5*5⌉**5)-55)',\n",
       " 189: '(⌊√55⌋*⌊.5*55⌋)',\n",
       " 190: '(5*⌈5*√55.5⌉)',\n",
       " 191: '⌈55*√⌊5+√55⌋⌉',\n",
       " 192: '(⌈5.55⌉/(.5**5))',\n",
       " 193: '⌊5!**(.55+.55)⌋',\n",
       " 194: '⌊(555-5!)/√5⌋',\n",
       " 195: '⌈(555-5!)/√5⌉',\n",
       " 196: '(.5*⌊√.5*555⌋)',\n",
       " 197: '⌈.5*⌈√.5*555⌉⌉',\n",
       " 198: '(⌊55/.55⌋/.5)',\n",
       " 199: '⌊55/(.5*.55)⌋',\n",
       " 200: '(⌈55/.55⌉/.5)',\n",
       " 201: '⌈555/(5-√5)⌉',\n",
       " 202: '⌊555/(.5+√5)⌋',\n",
       " 203: '⌊.5*⌊55*√55⌋⌋',\n",
       " 204: '(.5*⌈55*√55⌉)',\n",
       " 205: '(5*⌈5.5*√55⌉)',\n",
       " 206: '⌈⌈5!-√55⌉/.55⌉',\n",
       " 207: '⌊(5!-5)/.555⌋',\n",
       " 208: '⌈(5!-5)/.555⌉',\n",
       " 209: '(5.5*⌈5*√55⌉)',\n",
       " 210: '⌈⌈5!-5.5⌉/.55⌉',\n",
       " 211: '(⌊5!/.555⌋-5)',\n",
       " 212: '(⌈5!/.555⌉-5)',\n",
       " 213: '⌈⌊5!/.55⌋-5.5⌉',\n",
       " 214: '⌈⌈5!/.55⌉-5.5⌉',\n",
       " 215: '⌊⌊5!/.555⌋-.5⌋',\n",
       " 216: '⌊5!/.5555⌋',\n",
       " 217: '⌈5!/.5555⌉',\n",
       " 218: '⌈.5*(555-5!)⌉',\n",
       " 219: '(5!+⌊55/.55⌋)',\n",
       " 220: '((5*55)-55)',\n",
       " 221: '(5+⌊5!/.555⌋)',\n",
       " 222: '(555/(.5*5))',\n",
       " 223: '⌊5.5+⌊5!/.55⌋⌋',\n",
       " 224: '⌊5.5+⌈5!/.55⌉⌋',\n",
       " 225: '⌊(5+5!)/.555⌋',\n",
       " 226: '⌈(5+5!)/.555⌉',\n",
       " 227: '⌈555/√⌈5.5⌉⌉',\n",
       " 228: '(⌊5!-5.55⌋/.5)',\n",
       " 229: '⌈(5!-5.55)/.5⌉',\n",
       " 230: '(5!+(55+55))',\n",
       " 231: '(5!+(555/5))',\n",
       " 232: '⌈(5!+√55)/.55⌉',\n",
       " 233: '⌈⌈5!+√55⌉/.55⌉',\n",
       " 234: '(5!+⌊5!-5.55⌋)',\n",
       " 235: '(5*⌊55-√55⌋)',\n",
       " 236: '⌊555/√5.5⌋',\n",
       " 237: '⌈555/√5.5⌉',\n",
       " 238: '⌈5*(55-√55)⌉',\n",
       " 239: '(5!+⌊5!-.555⌋)',\n",
       " 240: '(5*⌈55-√55⌉)',\n",
       " 241: '(5!+⌈5!+.555⌉)',\n",
       " 242: '(⌈5!+.555⌉/.5)',\n",
       " 243: '(⌈5*.555⌉**5)',\n",
       " 244: '⌊55*(5-.55)⌋',\n",
       " 245: '(5*⌊55-5.5⌋)',\n",
       " 246: '⌈(555-5)/√5⌉',\n",
       " 247: '⌊5*(55-5.5)⌋',\n",
       " 248: '⌊555.5/√5⌋',\n",
       " 249: '⌈555.5/√5⌉',\n",
       " 250: '(5*⌊55.5-5⌋)',\n",
       " 251: '⌈(5+555)/√5⌉',\n",
       " 252: '⌊5*(55.5-5)⌋',\n",
       " 253: '⌈5*(55.5-5)⌉',\n",
       " 254: '(5+⌈555/√5⌉)',\n",
       " 255: '(5*⌈55.5-5⌉)',\n",
       " 256: '(⌊55*√5.5⌋/.5)',\n",
       " 257: '⌊55/(.5/√5.5)⌋',\n",
       " 258: '(⌈55*√5.5⌉/.5)',\n",
       " 259: '⌊5!/(55.5/5!)⌋',\n",
       " 260: '(5*⌊55-√5.5⌋)',\n",
       " 261: '⌈(5*.55)**5.5⌉',\n",
       " 262: '⌈555/√(5-.5)⌉',\n",
       " 263: '⌊5*(55-√5.5)⌋',\n",
       " 264: '⌈5*(55-√5.5)⌉',\n",
       " 265: '(5*⌈55-√5.5⌉)',\n",
       " 266: '⌊5*(55.5-√5)⌋',\n",
       " 267: '⌊(5*55)-√55⌋',\n",
       " 268: '⌈(5*55)-√55⌉',\n",
       " 269: '⌊(5*55)-5.5⌋',\n",
       " 270: '(5*⌊55-.55⌋)',\n",
       " 271: '(⌈.5-5⌉+(5*55))',\n",
       " 272: '(⌊.5*555⌋-5)',\n",
       " 273: '(⌈.5*555⌉-5)',\n",
       " 274: '⌊(5*55)-.55⌋',\n",
       " 275: '(5*⌊55.55⌋)',\n",
       " 276: '⌈.55+(5*55)⌉',\n",
       " 277: '⌊5*55.55⌋',\n",
       " 278: '⌈5*55.55⌉',\n",
       " 279: '⌈.5+⌈.5*555⌉⌉',\n",
       " 280: '(5*⌈55.55⌉)',\n",
       " 281: '⌈5.5+(5*55)⌉',\n",
       " 282: '(5+⌊.5*555⌋)',\n",
       " 283: '(5+⌈.5*555⌉)',\n",
       " 284: '⌊5*((5**5)/55)⌋',\n",
       " 285: '(5*⌊√5+55.5⌋)',\n",
       " 286: '(5.5*⌊55-√5⌋)',\n",
       " 287: '(555-⌊√5*5!⌋)',\n",
       " 288: '(⌈55*√55⌉-5!)',\n",
       " 289: '⌈55*√(.5*55)⌉',\n",
       " 290: '(5*⌈√5+55.5⌉)',\n",
       " 291: '⌊5.5*⌈55-√5⌉⌋',\n",
       " 292: '⌈5.5*⌈55-√5⌉⌉',\n",
       " 293: '⌊5!*√⌈5.555⌉⌋',\n",
       " 294: '⌈5!*√⌈5.555⌉⌉',\n",
       " 295: '(5!+⌊5!+55.5⌋)',\n",
       " 296: '(5!+⌈5!+55.5⌉)',\n",
       " 297: '(⌊5.5*55⌋-5)',\n",
       " 298: '(⌈5.5*55⌉-5)',\n",
       " 299: '⌊5.5*(55-.5)⌋',\n",
       " 300: '(5*⌊5+55.5⌋)',\n",
       " 301: '⌊⌊5.5*55⌋-.5⌋',\n",
       " 302: '⌊5*(5+55.5)⌋',\n",
       " 303: '⌈5*(5+55.5)⌉',\n",
       " 304: '⌈.5+⌈5.5*55⌉⌉',\n",
       " 305: '⌊.55*555⌋',\n",
       " 306: '⌈.55*555⌉',\n",
       " 307: '(5+⌊5.5*55⌋)',\n",
       " 308: '(5+⌈5.5*55⌉)',\n",
       " 309: '(⌈(√.5+5)*55⌉-5)',\n",
       " 310: '(5*⌊55+√55⌋)',\n",
       " 311: '⌈(√5**5)*5.55⌉',\n",
       " 312: '⌊5*(55+√55)⌋',\n",
       " 313: '⌈5*(55+√55)⌉',\n",
       " 314: '⌈5.5*⌊√5+55⌋⌉',\n",
       " 315: '(5*⌈55+√55⌉)',\n",
       " 316: '⌊√(55/5.5)**5⌋',\n",
       " 317: '⌈√(55/5.5)**5⌉',\n",
       " 318: '⌊(5!+55)/.55⌋',\n",
       " 319: '⌈(5!+55)/.55⌉',\n",
       " 320: '(5*⌊5!-55.5⌋)',\n",
       " 321: '⌊⌈5.555⌉!/√5⌋',\n",
       " 322: '⌊5*(5!-55.5)⌋',\n",
       " 323: '⌈5*(5!-55.5)⌉',\n",
       " 324: '(⌈5.5⌉*⌊55-.5⌋)',\n",
       " 325: '(5*⌈5!-55.5⌉)',\n",
       " 326: '⌈(5!/55)**√55⌉',\n",
       " 327: '(⌈5.5⌉*(55-.5))',\n",
       " 328: '⌈.5*(55+(5*5!))⌉',\n",
       " 329: '⌊(55*⌈5.5⌉)-.5⌋',\n",
       " 330: '(55*⌈5.55⌉)',\n",
       " 331: '⌈.5+(55*⌈5.5⌉)⌉',\n",
       " 332: '⌊.55*(5+(5*5!))⌋',\n",
       " 333: '(⌈5.5⌉*55.5)',\n",
       " 334: '⌈5*(5!*.555)⌉',\n",
       " 335: '(5*⌈5!*.555⌉)',\n",
       " 336: '(5!+⌊5!/.555⌋)',\n",
       " 337: '⌊.5*(5!+555)⌋',\n",
       " 338: '⌈.5*(5!+555)⌉',\n",
       " 339: '⌊55*√⌈5*√55⌉⌋',\n",
       " 340: '⌈55*√⌈5*√55⌉⌉',\n",
       " 341: '⌊55*(√.5+5.5)⌋',\n",
       " 342: '⌈55*(√.5+5.5)⌉',\n",
       " 343: '⌊5*(.55*(5+5!))⌋',\n",
       " 344: '⌈5*(.55*(5+5!))⌉',\n",
       " 345: '(5*⌈.55*(5+5!)⌉)',\n",
       " 346: '(⌊55*√(5+5)⌋/.5)',\n",
       " 347: '⌊5!*(.55+√5.5)⌋',\n",
       " 348: '(⌈5.5⌉*⌈√5+55⌉)',\n",
       " 349: '(⌊(5-.55)**5⌋/5)',\n",
       " 350: '(⌊5!+55.5⌋/.5)',\n",
       " 351: '((5!+55.5)/.5)',\n",
       " 352: '(⌈5!+55.5⌉/.5)',\n",
       " 353: '⌈⌈555/√5⌉/√.5⌉',\n",
       " 354: '⌊(.5*⌈5.5⌉!)-5.5⌋',\n",
       " 355: '(5*(5+(5!*.55)))',\n",
       " 356: '⌈(55/5)**√⌈5.5⌉⌉',\n",
       " 357: '⌊5.5*(5!-55)⌋',\n",
       " 358: '⌈5.5*(5!-55)⌉',\n",
       " 359: '⌊.5*⌊⌈5.55⌉!-.5⌋⌋',\n",
       " 360: '(.5*⌈5.555⌉!)',\n",
       " 361: '⌊(√5+5)*(55-5)⌋',\n",
       " 362: '⌊.5*(5+⌈5.55⌉!)⌋',\n",
       " 363: '(5.5*(5!*.55))',\n",
       " 364: '⌈5!*(.55*5.5)⌉',\n",
       " 365: '(5+(.5*⌈5.55⌉!))',\n",
       " 366: '(5!*(.55+(.5*5)))',\n",
       " 367: '(5!+⌊55*(5-.5)⌋)',\n",
       " 368: '(5!+⌊555/√5⌋)',\n",
       " 369: '(5!+⌈555/√5⌉)',\n",
       " 370: '⌊√55*(55-5)⌋',\n",
       " 371: '⌈√55*(55-5)⌉',\n",
       " 372: '(55+⌈√(5+5)**5⌉)',\n",
       " 373: '⌊55*√⌈5.5**√5⌉⌋',\n",
       " 374: '⌈55*√⌈5.5**√5⌉⌉',\n",
       " 375: '(5*⌈(5+5)*√55⌉)',\n",
       " 376: '(55+⌊⌈5.5⌉!/√5⌋)',\n",
       " 377: '(55+⌈⌈5.5⌉!/√5⌉)',\n",
       " 378: '(⌊√55⌋*⌊55-.5⌋)',\n",
       " 379: '⌊5!*√(55/5.5)⌋',\n",
       " 380: '⌊55*(√55-.5)⌋',\n",
       " 381: '⌈55*(√55-.5)⌉',\n",
       " 382: '⌈55**(√55/5)⌉',\n",
       " 383: '(5!+⌊5*(55-√5)⌋)',\n",
       " 384: '⌊(55*⌊√55⌋)-.5⌋',\n",
       " 385: '(55*⌊√55.5⌋)',\n",
       " 386: '(555-⌊5!/√.5⌋)',\n",
       " 387: '(⌊√.5*555⌋-5)',\n",
       " 388: '⌊⌊√55⌋*55.5⌋',\n",
       " 389: '⌈⌊√55⌋*55.5⌉',\n",
       " 390: '(5*⌊55.5/√.5⌋)',\n",
       " 391: '⌊⌊√.5*555⌋-.5⌋',\n",
       " 392: '⌊√.5*555.5⌋',\n",
       " 393: '⌈√.5*555.5⌉',\n",
       " 394: '⌈√.5*⌈555.5⌉⌉',\n",
       " 395: '⌊√.5*(5+555)⌋',\n",
       " 396: '⌊.55*⌈5.55⌉!⌋',\n",
       " 397: '(5!+⌊.5*555⌋)',\n",
       " 398: '(5!+⌈.5*555⌉)',\n",
       " 399: '⌊⌈5.5⌉!*.555⌋',\n",
       " 400: '⌈⌈5.5⌉!*.555⌉',\n",
       " 401: '⌊(√5+5)*55.5⌋',\n",
       " 402: '(⌊55*√55⌋-5)',\n",
       " 403: '(⌈55*√55⌉-5)',\n",
       " 404: '⌊√55*(55-.5)⌋',\n",
       " 405: '⌈√55*(55-.5)⌉',\n",
       " 406: '⌊⌊55*√55⌋-.5⌋',\n",
       " 407: '⌊55*√⌊55.5⌋⌋',\n",
       " 408: '⌈55*√⌊55.5⌋⌉',\n",
       " 409: '⌊55*√55.5⌋',\n",
       " 410: '⌈55*√55.5⌉',\n",
       " 411: '⌊√55*55.5⌋',\n",
       " 412: '⌈√55*55.5⌉',\n",
       " 413: '(5+⌈55*√55⌉)',\n",
       " 414: '⌈√55.5**⌈.5*5⌉⌉',\n",
       " 415: '⌊√55*⌈55.5⌉⌋',\n",
       " 416: '⌈√55*⌈55.5⌉⌉',\n",
       " 417: '⌊5*(5**(5*.55))⌋',\n",
       " 418: '⌊55*√⌈√5+55⌉⌋',\n",
       " 419: '⌊(5**5)/√55.5⌋',\n",
       " 420: '⌊⌈5*.55⌉**5.5⌋',\n",
       " 421: '⌈⌈5*.55⌉**5.5⌉',\n",
       " 422: '(5!+⌊5.5*55⌋)',\n",
       " 423: '(5!+⌈5.5*55⌉)',\n",
       " 424: '⌈5.5*⌊55/√.5⌋⌉',\n",
       " 425: '⌊55*(√5+5.5)⌋',\n",
       " 426: '⌊55*√(5+55)⌋',\n",
       " 427: '⌈55*√(5+55)⌉',\n",
       " 428: '⌊⌈5.5*55⌉/√.5⌋',\n",
       " 429: '(5.5*⌈55/√.5⌉)',\n",
       " 430: '(555-(5+5!))',\n",
       " 431: '⌈√55*⌈√5+55⌉⌉',\n",
       " 432: '(555-⌈√5+5!⌉)',\n",
       " 433: '(555-⌊√5+5!⌋)',\n",
       " 434: '(555-⌈.5+5!⌉)',\n",
       " 435: '⌊555.5-5!⌋',\n",
       " 436: '⌈555.5-5!⌉',\n",
       " 437: '(⌊√5-5!⌋+555)',\n",
       " 438: '(⌈√5-5!⌉+555)',\n",
       " 439: '⌊(⌈√55⌉*55)-.5⌋',\n",
       " 440: '(5+(555-5!))',\n",
       " 441: '⌈.5+(⌈√55⌉*55)⌉',\n",
       " 442: '(5+⌈5!/(.5*.55)⌉)',\n",
       " 443: '⌊55*√(5!-55)⌋',\n",
       " 444: '(⌈√55⌉*55.5)',\n",
       " 445: '⌈√55*(5+55)⌉',\n",
       " 446: '⌊55*√(5!*.55)⌋',\n",
       " 447: '⌊⌈√5⌉**5.555⌋',\n",
       " 448: '⌈⌈√5⌉**5.555⌉',\n",
       " 449: '⌈55*(5+√(5+5))⌉',\n",
       " 450: '(5!+(55*⌈5.5⌉))',\n",
       " 451: '⌊5!*(⌈5.55⌉-√5)⌋',\n",
       " 452: '⌊55*(√5+⌈5.5⌉)⌋',\n",
       " 453: '⌈55*(√5+⌈5.5⌉)⌉',\n",
       " 454: '(⌊(5+5!)/.55⌋/.5)',\n",
       " 455: '(⌊√55⌋*(5!-55))',\n",
       " 456: '⌊5.5*⌊√5**5.5⌋⌋',\n",
       " 457: '⌈5.5*⌊√5**5.5⌋⌉',\n",
       " 458: '(⌊5-.5⌋*(5!-5.5))',\n",
       " 459: '⌊555/(.5+√.5)⌋',\n",
       " 460: '⌈555/(.5+√.5)⌉',\n",
       " 461: '⌈55*√⌊√5.5**5⌋⌉',\n",
       " 462: '(5.5*⌈√5**5.5⌉)',\n",
       " 463: '⌈5*(5!-(.5*55))⌉',\n",
       " 464: '(⌈√55⌉*⌈√5+55⌉)',\n",
       " 465: '(5*(5!-⌊.5*55⌋))',\n",
       " 466: '⌊⌊√.5*5!⌋*5.55⌋',\n",
       " 467: '⌊55*(.5+⌈√55⌉)⌋',\n",
       " 468: '(5!*(5-(5.5/5)))',\n",
       " 469: '⌊55*(5+(√.5*5))⌋',\n",
       " 470: '(555-⌈√.5*5!⌉)',\n",
       " 471: '(555-⌊√.5*5!⌋)',\n",
       " 472: '⌈⌈√.5*5!⌉*5.55⌉',\n",
       " 473: '(5.5*⌈5**(5-√5)⌉)',\n",
       " 474: '(5!*(5-(.5+.55)))',\n",
       " 475: '((5!*⌊5-.55⌋)-5)',\n",
       " 476: '(55+⌈⌈√5⌉**5.5⌉)',\n",
       " 477: '⌊√.5*(5!+555)⌋',\n",
       " 478: '⌈√.5*(5!+555)⌉',\n",
       " 479: '((5*5!)-⌈5!+.55⌉)',\n",
       " 480: '(5!*⌊5-.555⌋)',\n",
       " 481: '((5*5!)-⌊5!-.55⌋)',\n",
       " 482: '⌊√55*(5!-55)⌋',\n",
       " 483: '⌈√55*(5!-55)⌉',\n",
       " 484: '⌈(√5*5!)/.555⌉',\n",
       " 485: '⌊√5*⌈5!/.555⌉⌋',\n",
       " 486: '⌈√5*⌈5!/.555⌉⌉',\n",
       " 487: '⌊5!/(.55**√5.5)⌋',\n",
       " 488: '⌊.55*⌊5!*√55⌋⌋',\n",
       " 489: '⌊.55*⌈5!*√55⌉⌋',\n",
       " 490: '⌈.55*⌈5!*√55⌉⌉',\n",
       " 491: '⌈5!*((5/.55)-5)⌉',\n",
       " 492: '(⌊5-.5⌋*⌈√5*55⌉)',\n",
       " 493: '⌈(⌊5/.55⌋**5)/5!⌉',\n",
       " 494: '(⌊55*(5-.5)⌋/.5)',\n",
       " 495: '(5*⌊55/.55⌋)',\n",
       " 496: '(⌊555/√5⌋/.5)',\n",
       " 497: '⌈555/(.5*√5)⌉',\n",
       " 498: '(⌈555/√5⌉/.5)',\n",
       " 499: '⌊5*(55/.55)⌋',\n",
       " 500: '(555-55)',\n",
       " 501: '(555-⌈5!/√5⌉)',\n",
       " 502: '(555-⌊5!/√5⌋)',\n",
       " 503: '⌊⌊5.5**5⌋/(5+5)⌋',\n",
       " 504: '⌈⌊5.5**5⌋/(5+5)⌉',\n",
       " 505: '(5!+(55*⌊√55⌋))',\n",
       " 506: '⌊(5-.5)*(5!-√55)⌋',\n",
       " 507: '(⌊5*(5!+5.5)⌋-5!)',\n",
       " 508: '(⌈5*(5!+5.5)⌉-5!)',\n",
       " 509: '⌊√.5*⌈5.555⌉!⌋',\n",
       " 510: '⌈√.5*⌈5.555⌉!⌉',\n",
       " 511: '⌈⌊5!*√5.5⌋/.55⌉',\n",
       " 512: '(5!+⌊√.5*555⌋)',\n",
       " 513: '(5!+⌈√.5*555⌉)',\n",
       " 514: '⌈√5.5*⌈5!/.55⌉⌉',\n",
       " 515: '(5!+(5!+(5*55)))',\n",
       " 516: '(5!+⌊.55*⌈5.5⌉!⌋)',\n",
       " 517: '(5!+⌈.55*⌈5.5⌉!⌉)',\n",
       " 518: '(555-⌈5**√5⌉)',\n",
       " 519: '(555-⌊5**√5⌋)',\n",
       " 520: '((5*(5!-5))-55)',\n",
       " 521: '⌈(5**5)/⌈5.55⌉⌉',\n",
       " 522: '⌊55*(5+(5-.5))⌋',\n",
       " 523: '⌈55*(5+(5-.5))⌉',\n",
       " 524: '(⌈5!*(5!/55)⌉/.5)',\n",
       " 525: '(5*((55/.5)-5))',\n",
       " 526: '(⌊5*(55-√5)⌋/.5)',\n",
       " 527: '(5!+⌊55*√55⌋)',\n",
       " 528: '(5!+⌈55*√55⌉)',\n",
       " 529: '((5!*(5-.55))-5)',\n",
       " 530: '(555-(5*5))',\n",
       " 531: '(555-(5!/5))',\n",
       " 532: '⌊5**(5-(5.5/5))⌋',\n",
       " 533: '⌊5!*(5-.555)⌋',\n",
       " 534: '⌈5!*(5-.555)⌉',\n",
       " 535: '(55+(5!*⌊5-.5⌋))',\n",
       " 536: '⌈(5-.5)*⌊5!-.55⌋⌉',\n",
       " 537: '⌊5.5*((.5*5)**5)⌋',\n",
       " 538: '⌈5.5*((.5*5)**5)⌉',\n",
       " 539: '(5+(5!*(5-.55)))',\n",
       " 540: '((5+5)*⌊55-.5⌋)',\n",
       " 541: '⌈.55+(5!*(5-.5))⌉',\n",
       " 542: '(⌊5*(5!-.5)⌋-55)',\n",
       " 543: '(555-⌈√5*5⌉)',\n",
       " 544: '(555-⌊√5*5⌋)',\n",
       " 545: '(555-(5+5))',\n",
       " 546: '((5!*5.55)-5!)',\n",
       " 547: '⌊555-√55⌋',\n",
       " 548: '⌈555-√55⌉',\n",
       " 549: '⌊555-5.5⌋',\n",
       " 550: '⌈555-5.5⌉',\n",
       " 551: '⌈555.5-5⌉',\n",
       " 552: '⌊555-√5.5⌋',\n",
       " 553: '⌊555.5-√5⌋',\n",
       " 554: '⌊555-.55⌋',\n",
       " 555: '⌊555.55⌋',\n",
       " 556: '⌈555.55⌉',\n",
       " 557: '⌊√5+555.5⌋',\n",
       " 558: '⌈√5+555.5⌉',\n",
       " 559: '(5+⌊555-.5⌋)',\n",
       " 560: '⌊5+555.5⌋',\n",
       " 561: '⌈5+555.5⌉',\n",
       " 562: '⌊√55+555⌋',\n",
       " 563: '⌈√55+555⌉',\n",
       " 564: '⌈(5**5)/5.55⌉',\n",
       " 565: '(5+(5+555))',\n",
       " 566: '(⌊√5*5⌋+555)',\n",
       " 567: '(⌈√5*5⌉+555)',\n",
       " 568: '(⌈5*(5!-5.5)⌉-5)',\n",
       " 569: '⌊(5*(5!-5))-5.5⌋',\n",
       " 570: '(5*⌊5!-5.55⌋)',\n",
       " 571: '⌊√55*⌊55/√.5⌋⌋',\n",
       " 572: '⌊5*(5!-5.55)⌋',\n",
       " 573: '⌈5*(5!-5.55)⌉',\n",
       " 574: '(5+⌈(5**5)/5.5⌉)',\n",
       " 575: '(5*⌈5!-5.55⌉)',\n",
       " 576: '⌈.55+(5*(5!-5))⌉',\n",
       " 577: '⌊55*(5+5.5)⌋',\n",
       " 578: '⌈55*(5+5.5)⌉',\n",
       " 579: '((5!/5)+555)',\n",
       " 580: '((5*5)+555)',\n",
       " 581: '⌈5.5+(5*(5!-5))⌉',\n",
       " 582: '⌈5!*(5.55-√.5)⌉',\n",
       " 583: '(55/(5/⌊5!/√5⌋))',\n",
       " 584: '⌈5*(5!-√(55/5))⌉',\n",
       " 585: '(5*(5!-⌈5*.55⌉))',\n",
       " 586: '⌊5*(5!-(5*.55))⌋',\n",
       " 587: '((⌊√5⌋**5)+555)',\n",
       " 588: '⌈5!*√⌊5-.555⌋!⌉',\n",
       " 589: '((5*5!)-(55/5))',\n",
       " 590: '⌈5!*(5-(5/55))⌉',\n",
       " 591: '(⌊5**√5⌋+555)',\n",
       " 592: '(⌈5**√5⌉+555)',\n",
       " 593: '⌈(5*5!)-√55.5⌉',\n",
       " 594: '⌊(5*5!)-5.55⌋',\n",
       " 595: '(5*⌊5!-.555⌋)',\n",
       " 596: '⌈√(5+5)**5.55⌉',\n",
       " 597: '⌊5*(5!-.555)⌋',\n",
       " 598: '⌈5*(5!-.555)⌉',\n",
       " 599: '⌊(5*5!)-.555⌋',\n",
       " 600: '(5*⌊5.555⌋!)',\n",
       " 601: '⌈(5*5!)+.555⌉',\n",
       " 602: '⌊5*(5!+.555)⌋',\n",
       " 603: '⌈5*(5!+.555)⌉',\n",
       " 604: '(⌊5.5*55⌋/.5)',\n",
       " 605: '(55*(55/5))',\n",
       " 606: '(⌈5.5*55⌉/.5)',\n",
       " 607: '⌊(5*5!)+√55.5⌋',\n",
       " 608: '(⌊5!/√5⌋+555)',\n",
       " 609: '(⌈5!/√5⌉+555)',\n",
       " 610: '(55+555)',\n",
       " 611: '(⌈√5**5⌉+555)',\n",
       " 612: '(5+⌊(5*5!)+√55⌋)',\n",
       " 613: '⌊5*(5!+(5*.55))⌋',\n",
       " 614: '(((5**5)-55)/5)',\n",
       " 615: '((.5*5!)+555)',\n",
       " 616: '(5.5*⌊5!-√55⌋)',\n",
       " 617: '⌊5*(.5+⌈√5*55⌉)⌋',\n",
       " 618: '⌈5*(.5+⌈√5*55⌉)⌉',\n",
       " 619: '⌊√5*⌊.5*555⌋⌋',\n",
       " 620: '(5*⌊√5*55.5⌋)',\n",
       " 621: '(.5*⌈√5*555⌉)',\n",
       " 622: '⌈√5*⌈.5*555⌉⌉',\n",
       " 623: '⌊5!*√⌊5*5.55⌋⌋',\n",
       " 624: '⌈5!*√⌊5*5.55⌋⌉',\n",
       " 625: '(5**⌊5-.555⌋)',\n",
       " 626: '(⌊5.5+(5**5)⌋/5)',\n",
       " 627: '⌊5*(5!+5.55)⌋',\n",
       " 628: '⌈5*(5!+5.55)⌉',\n",
       " 629: '⌊5.5*(5!-5.5)⌋',\n",
       " 630: '(5*⌈5!+5.55⌉)',\n",
       " 631: '⌈5.5+(5*(5+5!))⌉',\n",
       " 632: '⌊5.5*⌈5!-5.5⌉⌋',\n",
       " 633: '⌈5.5*⌈5!-5.5⌉⌉',\n",
       " 634: '⌊5!*√⌈5*5.55⌉⌋',\n",
       " 635: '(5*⌊5!+√55.5⌋)',\n",
       " 636: '(((5**5)+55)/5)',\n",
       " 637: '⌊5*(5!+√55.5)⌋',\n",
       " 638: '⌊(5!-5)*5.55⌋',\n",
       " 639: '⌈(5!-5)*5.55⌉',\n",
       " 640: '(5*⌊55*√5.5⌋)',\n",
       " 641: '⌈.5+(5*⌈5!+√55⌉)⌉',\n",
       " 642: '(5+⌊5*(5!+√55)⌋)',\n",
       " 643: '⌊5.5*⌊5!-√5.5⌋⌋',\n",
       " 644: '⌊5*(55*√5.5)⌋',\n",
       " 645: '(5*⌈55*√5.5⌉)',\n",
       " 646: '⌈5*(5!+(5/.55))⌉',\n",
       " 647: '⌊5.5*(5!-√5.5)⌋',\n",
       " 648: '(5!*(⌊.5*55⌋/5))',\n",
       " 649: '⌊⌊5!-√5⌋*5.55⌋',\n",
       " 650: '((5+5)*(5!-55))',\n",
       " 651: '(⌈√5⌉*⌈5!/.555⌉)',\n",
       " 652: '⌊(5!*5.5)-√55⌋',\n",
       " 653: '⌊(5!-√5)*5.55⌋',\n",
       " 654: '⌊5.5*⌊5!-.55⌋⌋',\n",
       " 655: '⌊(5*5!)+55.5⌋',\n",
       " 656: '⌈(5*5!)+55.5⌉',\n",
       " 657: '⌈5.5*(5!-.55)⌉',\n",
       " 658: '⌈5!*√⌊.55*55⌋⌉',\n",
       " 659: '⌊(5!*5.5)-.55⌋',\n",
       " 660: '(5.5*⌊5.55⌋!)',\n",
       " 661: '((5!*5.55)-5)',\n",
       " 662: '⌊(5!-√.5)*5.55⌋',\n",
       " 663: '⌊5.5*(5!+.55)⌋',\n",
       " 664: '⌊⌈5.5⌉!-55.5⌋',\n",
       " 665: '(⌈5.55⌉!-55)',\n",
       " 666: '⌊5!*5.555⌋',\n",
       " 667: '⌈5!*5.555⌉',\n",
       " 668: '⌊(.5+5!)*5.55⌋',\n",
       " 669: '⌈(.5+5!)*5.55⌉',\n",
       " 670: '(5!+(555-5))',\n",
       " 671: '(5+(5!*5.55))',\n",
       " 672: '(5!+⌊555-√5⌋)',\n",
       " 673: '(5!+⌈555-√5⌉)',\n",
       " 674: '(5!+⌊555-.5⌋)',\n",
       " 675: '⌊5!+555.5⌋',\n",
       " 676: '⌈5!+555.5⌉',\n",
       " 677: '(5!+⌊√5+555⌋)',\n",
       " 678: '(5!+⌈√5+555⌉)',\n",
       " 679: '⌈(5.5**5)/√55⌉',\n",
       " 680: '(5+(5!+555))',\n",
       " 681: '⌈5!*(5+(5/√55))⌉',\n",
       " 682: '⌊55*(5+√55)⌋',\n",
       " 683: '⌈55*(5+√55)⌉',\n",
       " 684: '(⌈5.5⌉*⌊5!-5.5⌋)',\n",
       " 685: '(5*⌊.5*(5*55)⌋)',\n",
       " 686: '⌊(√5-⌈.5⌉)*555⌋',\n",
       " 687: '⌊5.5*⌊5!+5.5⌋⌋',\n",
       " 688: '⌈5.5*⌊5!+5.5⌋⌉',\n",
       " 689: '(5!+⌈(5**5)/5.5⌉)',\n",
       " 690: '⌊5.5*(5!+5.5)⌋',\n",
       " 691: '⌈5.5*(5!+5.5)⌉',\n",
       " 692: '(5+⌊5.5*(5+5!)⌋)',\n",
       " 693: '⌊(5+5!)*5.55⌋',\n",
       " 694: '⌈(5+5!)*5.55⌉',\n",
       " 695: '(⌈5.55⌉!-(5*5))',\n",
       " 696: '(⌈5.55⌉!-(5!/5))',\n",
       " 697: '(⌈(.5*√55)**5⌉-5)',\n",
       " 698: '⌊5.5*⌊5!+√55⌋⌋',\n",
       " 699: '⌈5.5*⌊5!+√55⌋⌉',\n",
       " 700: '(5*(5*⌈.5*55⌉))',\n",
       " 701: '⌈5.5*(5!+√55)⌉',\n",
       " 702: '⌊(5**5)/(5-.55)⌋',\n",
       " 703: '⌈(5**5)/(5-.55)⌉',\n",
       " 704: '(5.5*⌈5!+√55⌉)',\n",
       " 705: '(5*(5!+⌊5!/5.5⌋))',\n",
       " 706: '⌊(5!-√5)*⌈5.55⌉⌋',\n",
       " 707: '(⌈5.5⌉!-⌈5+√55⌉)',\n",
       " 708: '(⌈5!-√5⌉*⌈5.55⌉)',\n",
       " 709: '(⌈5.5⌉!-(55/5))',\n",
       " 710: '(⌈5.55⌉!-(5+5))',\n",
       " 711: '(⌈5.5⌉!-⌊5/.55⌋)',\n",
       " 712: '⌊⌈5.55⌉!-√55⌋',\n",
       " 713: '⌈⌈5.55⌉!-√55⌉',\n",
       " 714: '⌊⌈5.55⌉!-5.5⌋',\n",
       " 715: '(⌈5.555⌉!-5)',\n",
       " 716: '(⌈5.5⌉!-⌊5-.55⌋)',\n",
       " 717: '⌊⌈5.555⌉!-√5⌋',\n",
       " 718: '⌈⌈5.555⌉!-√5⌉',\n",
       " 719: '⌊⌈5.555⌉!-.5⌋',\n",
       " 720: '⌈5.5555⌉!',\n",
       " 721: '⌈.5+⌈5.555⌉!⌉',\n",
       " 722: '⌊√5+⌈5.555⌉!⌋',\n",
       " 723: '⌈√5+⌈5.555⌉!⌉',\n",
       " 724: '(⌊5!/√.5⌋+555)',\n",
       " 725: '(5+⌈5.555⌉!)',\n",
       " 726: '⌈5.5+⌈5.55⌉!⌉',\n",
       " 727: '⌊√55+⌈5.55⌉!⌋',\n",
       " 728: '⌈√55+⌈5.55⌉!⌉',\n",
       " 729: '(⌈√5⌉**⌈5.555⌉)',\n",
       " 730: '(5+(5+⌈5.55⌉!))',\n",
       " 731: '(⌈5.5⌉!+(55/5))',\n",
       " 732: '(5!*(5+(5.5/5)))',\n",
       " 733: '(5+⌈⌈5.5⌉!+√55⌉)',\n",
       " 734: '(5!+⌊√5*(5*55)⌋)',\n",
       " 735: '(5*(5!+⌊.5*55⌋))',\n",
       " 736: '⌊√5.5**√(5+55)⌋',\n",
       " 737: '⌊5*(5!+(.5*55))⌋',\n",
       " 738: '(⌈5.5⌉*⌈√5*55⌉)',\n",
       " 739: '⌊5!*√⌈5*√55.5⌉⌋',\n",
       " 740: '(5*(5!+⌈.5*55⌉))',\n",
       " 741: '(⌈5.5⌉!+⌊5!/5.5⌋)',\n",
       " 742: '(⌈5.5⌉!+⌈5!/5.5⌉)',\n",
       " 743: '⌊⌊5!**√5⌋/(5+55)⌋',\n",
       " 744: '((5!/5)+⌈5.55⌉!)',\n",
       " 745: '((5*5)+⌈5.55⌉!)',\n",
       " 746: '(5!+((5+(5**5))/5))',\n",
       " 747: '(⌈5.5⌉!+⌊.5*55⌋)',\n",
       " 748: '(⌈5.5⌉!+⌈.5*55⌉)',\n",
       " 749: '⌈5!*(√5+⌊5-.55⌋)⌉',\n",
       " 750: '((5+5!)*⌈5.55⌉)',\n",
       " 751: '⌈5!*(√.5+5.55)⌉',\n",
       " 752: '(5!+⌊5.5*(5!-5)⌋)',\n",
       " 753: '(⌈5.5⌉*(5!+5.5))',\n",
       " 754: '(5!+⌊5!*√⌈.5*55⌉⌋)',\n",
       " 755: '((5*(5!+55))-5!)',\n",
       " 756: '(⌈5.5⌉*⌈5!+5.5⌉)',\n",
       " 757: '(⌈5.5⌉!+⌊5*√55⌋)',\n",
       " 758: '(⌈5.5⌉!+⌈5*√55⌉)',\n",
       " 759: '⌈5!*√⌊5.5*√55⌋⌉',\n",
       " 760: '(5*⌊55*(5-√5)⌋)',\n",
       " 761: '⌈5*(55*(5-√5))⌉',\n",
       " 762: '(⌈5.5⌉*⌊5!+√55⌋)',\n",
       " 763: '⌈5*(5!**(.5+.55))⌉',\n",
       " 764: '⌊⌈5.5⌉*(5!+√55)⌋',\n",
       " 765: '(5*⌈55*(5-√5)⌉)',\n",
       " 766: '⌈(⌈√5⌉**5.5)/.55⌉',\n",
       " 767: '⌈((5*5)-5.5)**√5⌉',\n",
       " 768: '⌊√⌈5.55⌉**√55⌋',\n",
       " 769: '⌊55**√(5*.55)⌋',\n",
       " 770: '(55*⌊√55/.5⌋)',\n",
       " 771: '⌈(5*5.55)**⌊√5⌋⌉',\n",
       " 772: '(55+⌊⌈5.5⌉!-√5⌋)',\n",
       " 773: '(⌊5!*√55.5⌋-5!)',\n",
       " 774: '(55+⌊⌈5.5⌉!-.5⌋)',\n",
       " 775: '(55+⌈5.55⌉!)',\n",
       " 776: '⌈⌈5.5⌉!+55.5⌉',\n",
       " 777: '⌊(555-5)/√.5⌋',\n",
       " 778: '⌈(555-5)/√.5⌉',\n",
       " 779: '(⌊555/√.5⌋-5)',\n",
       " 780: '(⌈555/√.5⌉-5)',\n",
       " 781: '⌊(5**5)/⌊5-.55⌋⌋',\n",
       " 782: '⌈(5**5)/⌊5-.55⌋⌉',\n",
       " 783: '⌊⌊555/√.5⌋-.5⌋',\n",
       " 784: '⌊√⌊.5*5⌋*555⌋',\n",
       " 785: '⌊555.5/√.5⌋',\n",
       " 786: '⌈555.5/√.5⌉',\n",
       " 787: '⌈⌈555.5⌉/√.5⌉',\n",
       " 788: '⌈(5-.5)*(5!+55)⌉',\n",
       " 789: '(5+⌊555/√.5⌋)',\n",
       " 790: '(5+⌈555/√.5⌉)',\n",
       " 791: '⌊(5+555)/√.5⌋',\n",
       " 792: '⌈(5+555)/√.5⌉',\n",
       " 793: '⌈⌈5.5⌉!*(5.5/5)⌉',\n",
       " 794: '(⌈.55*⌈5.5⌉!⌉/.5)',\n",
       " 795: '(5!+(5!+555))',\n",
       " 796: '⌈55**(5/⌈.5*5⌉)⌉',\n",
       " 797: '⌊5.5*(5!+(5*5))⌋',\n",
       " 798: '((⌈√5⌉**5)+555)',\n",
       " 799: '⌈5!*(5+√(5*.55))⌉',\n",
       " 800: '(5*((⌈√5⌉*55)-5))',\n",
       " 801: '⌊⌊√55⌋*(5!-5.5)⌋',\n",
       " 802: '⌈⌊√55⌋*(5!-5.5)⌉',\n",
       " 803: '⌊⌊5!**√5⌋/55.5⌋',\n",
       " 804: '⌈⌊5!**√5⌋/55.5⌉',\n",
       " 805: '((5!-5)*⌊√55.5⌋)',\n",
       " 806: '⌊(5-.5)**(5-.55)⌋',\n",
       " 807: '(5!+⌊5.5*(5+5!)⌋)',\n",
       " 808: '(5!+⌈5.5*(5+5!)⌉)',\n",
       " 809: '(⌊5!*√(5+55)⌋-5!)',\n",
       " 810: '(⌈√5⌉*((5*55)-5))',\n",
       " 811: '⌈(5+(5!**√5))/55⌉',\n",
       " 812: '⌈(5*⌊5-.55⌋)**√5⌉',\n",
       " 813: '(⌊5!*(√5+5)⌋-55)',\n",
       " 814: '(⌊55*√55⌋/.5)',\n",
       " 815: '⌊55/(.5/√55)⌋',\n",
       " 816: '(⌈55*√55⌉/.5)',\n",
       " 817: '⌊5**(5/(⌈5.5⌉/5))⌋',\n",
       " 818: '((5*5!)+⌊5!/.55⌋)',\n",
       " 819: '((5*5!)+⌈5!/.55⌉)',\n",
       " 820: '((⌈√5⌉*(5*55))-5)',\n",
       " 821: '⌊5!/(√.5**5.55)⌋',\n",
       " 822: '⌊5!*√⌊55-√55⌋⌋',\n",
       " 823: '(⌊√5*5!⌋+555)',\n",
       " 824: '(⌈√5*5!⌉+555)',\n",
       " 825: '(55*(5+(5+5)))',\n",
       " 826: '⌊(5*5!)**(.5+.55)⌋',\n",
       " 827: '⌊(5-.55)**(5-.5)⌋',\n",
       " 828: '⌈(5-.55)**(5-.5)⌉',\n",
       " 829: '⌈(√5+5)*(5!-5.5)⌉',\n",
       " 830: '(5*⌊⌈√5⌉*55.5⌋)',\n",
       " 831: '(⌈√5⌉*⌊.5*555⌋)',\n",
       " 832: '⌊(.5+⌈.5⌉)*555⌋',\n",
       " 833: '⌈(.5+⌈.5⌉)*555⌉',\n",
       " 834: '(⌊5!*√55⌋-55)',\n",
       " 835: '(⌈5!*√55⌉-55)',\n",
       " 836: '⌊⌊√55⌋*(5!-.55)⌋',\n",
       " 837: '⌈⌊√55⌋*(5!-.55)⌉',\n",
       " 838: '⌊(5.5**5)/⌈5.5⌉⌋',\n",
       " 839: '⌈(5.5**5)/⌈5.5⌉⌉',\n",
       " 840: '(5!+⌈5.555⌉!)',\n",
       " 841: '(5!+⌈.5+⌈5.55⌉!⌉)',\n",
       " 842: '(⌈5.5⌉!+⌊√5*55⌋)',\n",
       " 843: '(⌈5.5⌉!+⌈√5*55⌉)',\n",
       " 844: '⌊5!*√(55-5.5)⌋',\n",
       " 845: '⌊√55*⌊5!-5.5⌋⌋',\n",
       " 846: '⌈√55*⌊5!-5.5⌋⌉',\n",
       " 847: '(⌊√55⌋*⌈5!+.55⌉)',\n",
       " 848: '⌊5!*√⌊55.5-5⌋⌋',\n",
       " 849: '⌊√55*(5!-5.5)⌋',\n",
       " 850: '(5*(5!+(55-5)))',\n",
       " 851: '⌊⌊(5!-5)*√55⌋-.5⌋',\n",
       " 852: '⌊5!*√(55.5-5)⌋',\n",
       " 853: '⌈5!*√(55.5-5)⌉',\n",
       " 854: '(5+⌈5!*√(55-5)⌉)',\n",
       " 855: '(5*⌈5.55**⌈√5⌉⌉)',\n",
       " 856: '⌊(5!-5)*√55.5⌋',\n",
       " 857: '⌈(5!-5)*√55.5⌉',\n",
       " 858: '(5+⌈(5!-5)*√55⌉)',\n",
       " 859: '⌊55**(√5-.55)⌋',\n",
       " 860: '⌈55**(√5-.55)⌉',\n",
       " 861: '⌊5!*(5+(5!/55))⌋',\n",
       " 862: '⌈5!*(5+(5!/55))⌉',\n",
       " 863: '⌈5**(⌊5!/5.5⌋/5)⌉',\n",
       " 864: '(⌊.5*55⌋/(.5**5))',\n",
       " 865: '(5*⌊55*√(5+5)⌋)',\n",
       " 866: '⌈5!*√⌊55-√5.5⌋⌉',\n",
       " 867: '⌊√55*⌊5!-√5.5⌋⌋',\n",
       " 868: '⌈√55*⌊5!-√5.5⌋⌉',\n",
       " 869: '⌊5*(55*√(5+5))⌋',\n",
       " 870: '((555-5!)/.5)',\n",
       " 871: '⌊5!**√⌈5.55/5⌉⌋',\n",
       " 872: '⌊5*(5!+(55-.5))⌋',\n",
       " 873: '⌈5*(5!+(55-.5))⌉',\n",
       " 874: '⌊(5*(5!+55))-.5⌋',\n",
       " 875: '(5*⌊5!+55.5⌋)',\n",
       " 876: '⌈.5+(5*(5!+55))⌉',\n",
       " 877: '⌊5*(5!+55.5)⌋',\n",
       " 878: '⌈5*(5!+55.5)⌉',\n",
       " 879: '⌈√5*⌈√.5*555⌉⌉',\n",
       " 880: '(5*⌈5!+55.5⌉)',\n",
       " 881: '⌊5!*√⌊55-.55⌋⌋',\n",
       " 882: '⌊√55*⌊5!-.55⌋⌋',\n",
       " 883: '⌊⌊5!*√55⌋-5.5⌋',\n",
       " 884: '⌊⌈5!*√55⌉-5.5⌋',\n",
       " 885: '⌈⌈5!*√55⌉-5.5⌉',\n",
       " 886: '⌈√55*(5!-.55)⌉',\n",
       " 887: '⌈⌊5!-.5⌋*√55.5⌉',\n",
       " 888: '(⌊5!*√55.5⌋-5)',\n",
       " 889: '⌊5!*(55/√55)⌋',\n",
       " 890: '⌈5!*(55/√55)⌉',\n",
       " 891: '⌈.55+(5!*√55)⌉',\n",
       " 892: '⌊⌊5!*√55.5⌋-.5⌋',\n",
       " 893: '⌊⌊5.5⌋!*√55.5⌋',\n",
       " 894: '⌊5.5+⌊5!*√55⌋⌋',\n",
       " 895: '⌈5.5+⌊5!*√55⌋⌉',\n",
       " 896: '⌈5.5+⌈5!*√55⌉⌉',\n",
       " 897: '⌊5!*√⌈55.55⌉⌋',\n",
       " 898: '⌈5!*√⌈55.55⌉⌉',\n",
       " 899: '(5+⌈5!*√55.5⌉)',\n",
       " 900: '(5*(5+(5!+55)))',\n",
       " 901: '⌊⌈.5+5!⌉*√55.5⌋',\n",
       " 902: '⌊(5-(5.5/5))**5⌋',\n",
       " 903: '⌈(5-(5.5/5))**5⌉',\n",
       " 904: '(5!+⌊555/√.5⌋)',\n",
       " 905: '(5!+⌈555/√.5⌉)',\n",
       " 906: '(⌈√5⌉*⌊5.5*55⌋)',\n",
       " 907: '⌊⌈√5⌉*(5.5*55)⌋',\n",
       " 908: '⌈⌈√5⌉*(5.5*55)⌉',\n",
       " 909: '(⌈√5⌉*⌈5.5*55⌉)',\n",
       " 910: '⌊√5*⌊55*√55⌋⌋',\n",
       " 911: '⌈√5*⌊55*√55⌋⌉',\n",
       " 912: '⌊√5*⌈55*√55⌉⌋',\n",
       " 913: '⌈√5*⌈55*√55⌉⌉',\n",
       " 914: '⌊⌊5.5**5⌋/5.5⌋',\n",
       " 915: '⌊5.5**⌊5-.55⌋⌋',\n",
       " 916: '⌈5.5**⌊5-.55⌋⌉',\n",
       " 917: '⌈⌈√5+5!⌉*√55.5⌉',\n",
       " 918: '⌊5.5*⌈5.5**⌈√5⌉⌉⌋',\n",
       " 919: '⌈5.5*⌈5.5**⌈√5⌉⌉⌉',\n",
       " 920: '(5+⌊5.5**⌊5-.5⌋⌋)',\n",
       " 921: '⌊(.5*5)**√55.5⌋',\n",
       " 922: '⌈(.5*5)**√55.5⌉',\n",
       " 923: '(55+⌊5!*(√5+5)⌋)',\n",
       " 924: '(55+⌈5!*(√5+5)⌉)',\n",
       " 925: '(5*(555/⌈√5⌉))',\n",
       " 926: '⌊⌊(5+5!)*√55⌋-.5⌋',\n",
       " 927: '⌊√55*⌊5!+5.5⌋⌋',\n",
       " 928: '⌈√55*⌊5!+5.5⌋⌉',\n",
       " 929: '⌊5!*√⌊5+55.5⌋⌋',\n",
       " 930: '⌈5!*√⌊5+55.5⌋⌉',\n",
       " 931: '⌊(5+5!)*√55.5⌋',\n",
       " 932: '⌈(5+5!)*√55.5⌉',\n",
       " 933: '⌊5!*√(5+55.5)⌋',\n",
       " 934: '⌈5!*√(5+55.5)⌉',\n",
       " 935: '(55*⌈5!/√55⌉)',\n",
       " 936: '⌈(5+5!)*√⌈55.5⌉⌉',\n",
       " 937: '⌊5!*√⌈5+55.5⌉⌋',\n",
       " 938: '⌈5!*√⌈5+55.5⌉⌉',\n",
       " 939: '⌊5.5/(.5**√55)⌋',\n",
       " 940: '⌈5.5/(.5**√55)⌉',\n",
       " 941: '⌊√55*⌊5!+√55⌋⌋',\n",
       " 942: '⌊⌊5**5.5⌋/√55⌋',\n",
       " 943: '⌈⌊5**5.5⌋/√55⌉',\n",
       " 944: '(55+⌊5!*√55⌋)',\n",
       " 945: '(55+⌈5!*√55⌉)',\n",
       " 946: '(5.5*⌊(5+5)**√5⌋)',\n",
       " 947: '⌊(√.5+⌈.5⌉)*555⌋',\n",
       " 948: '⌊5.55**⌊5-.5⌋⌋',\n",
       " 949: '⌈5.55**⌊5-.5⌋⌉',\n",
       " 950: '(5*(5*⌈5*√55⌉))',\n",
       " 951: '⌊5.5*⌈(5+5)**√5⌉⌋',\n",
       " 952: '⌊5!*√⌈55+√55⌉⌋',\n",
       " 953: '⌈5!*√⌈55+√55⌉⌉',\n",
       " 954: '⌊(5!+555)/√.5⌋',\n",
       " 955: '⌊5!*(.55+√55)⌋',\n",
       " 956: '⌈5!*(.55+√55)⌉',\n",
       " 957: '⌊5!*(.5+√⌈55.5⌉)⌋',\n",
       " 958: '⌈5!*(.5+√⌈55.5⌉)⌉',\n",
       " 959: '⌊(5!*⌈√55⌉)-.55⌋',\n",
       " 960: '(5!*⌈55/√55⌉)',\n",
       " 961: '⌊√⌈.5*5⌉*555⌋',\n",
       " 962: '⌊5.5*(5!+55)⌋',\n",
       " 963: '⌈5.5*(5!+55)⌉',\n",
       " 964: '⌈(√5-.5)*555⌉',\n",
       " 965: '⌊(5!/5.55)**√5⌋',\n",
       " 966: '⌈(5!/5.55)**√5⌉',\n",
       " 967: '⌊5!*√⌈5!-55.5⌉⌋',\n",
       " 968: '⌈5!*√⌈5!-55.5⌉⌉',\n",
       " 969: '((⌊5-.5⌋**5)-55)',\n",
       " 970: '(5*⌈5!**(5.5/5)⌉)',\n",
       " 971: '(⌈5*(5!/.55)⌉-5!)',\n",
       " 972: '⌊√5*(555-5!)⌋',\n",
       " 973: '⌈√5*(555-5!)⌉',\n",
       " 974: '⌊5!*√⌊5!*.555⌋⌋',\n",
       " 975: '⌈5!*√⌊5!*.555⌋⌉',\n",
       " 976: '(⌈√55⌉*⌊√5*55⌋)',\n",
       " 977: '⌈(5+5)*((.5*5)**5)⌉',\n",
       " 978: '⌊5!*(√.5+√55.5)⌋',\n",
       " 979: '⌊5!*(5+√⌊5+5.5⌋)⌋',\n",
       " 980: '⌈5!*(5+√⌊5+5.5⌋)⌉',\n",
       " 981: '((5-.5)*⌊5!/.55⌋)',\n",
       " 982: '⌊5!*√⌈5!*.555⌉⌋',\n",
       " 983: '⌈5!*√⌈5!*.555⌉⌉',\n",
       " 984: '(⌈√55⌉*⌈√5*55⌉)',\n",
       " 985: '⌊(5-.5)*⌈5!/.55⌉⌋',\n",
       " 986: '⌈(5-.5)*⌈5!/.55⌉⌉',\n",
       " 987: '⌊√⌈√5*5⌉**5.55⌋',\n",
       " 988: '⌊5!*(√5+⌈5.55⌉)⌋',\n",
       " 989: '⌈5!*(√5+⌈5.55⌉)⌉',\n",
       " 990: '((555/.5)-5!)',\n",
       " 991: '⌊5!*(5-(√5-5.5))⌋',\n",
       " 992: '⌈5!*(5-(√5-5.5))⌉',\n",
       " 993: '⌈√5*⌊⌈√5⌉**5.55⌋⌉',\n",
       " 994: '⌊5!*(5*√(5*.55))⌋',\n",
       " 995: '(⌈5.5⌉!+(5*55))',\n",
       " 996: '⌊⌈5**(5-√.5)⌉-5.5⌋',\n",
       " 997: '⌊5!*(5+√(55/5))⌋',\n",
       " 998: '⌊⌊5**5.5⌋/⌊√55⌋⌋',\n",
       " 999: '⌈⌊5**5.5⌋/⌊√55⌋⌉',\n",
       " ...}"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clear()\n",
    "\n",
    "%time makeable(ff)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "The output got truncated by Jupyter Notebook after 1000 entries. Let's see what the first unmakeable integer actually is:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23308"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unmakeable(ff)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "I think we've conquered the five 5s problem.\n",
    "\n",
    "# Conclusion\n",
    "\n",
    "We were able to solve the puzzles, and we now have some tools to explore new puzzles. What can you discover?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
